From 020721b33d1dce607ddd70ba0f0b56c7c37d5705 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Thu, 19 Mar 2020 21:44:49 -0500 Subject: [PATCH 1/2] fix: arbitrary abi formatting --- rustfmt-core/rustfmt-lib/src/utils.rs | 14 ++++++-------- .../rustfmt-lib/tests/source/issue_4086.rs | 2 ++ .../rustfmt-lib/tests/target/issue_4086.rs | 2 ++ 3 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 rustfmt-core/rustfmt-lib/tests/source/issue_4086.rs create mode 100644 rustfmt-core/rustfmt-lib/tests/target/issue_4086.rs diff --git a/rustfmt-core/rustfmt-lib/src/utils.rs b/rustfmt-core/rustfmt-lib/src/utils.rs index e3e07b44ebe..1c02e05b66c 100644 --- a/rustfmt-core/rustfmt-lib/src/utils.rs +++ b/rustfmt-core/rustfmt-lib/src/utils.rs @@ -140,19 +140,17 @@ pub(crate) fn format_extern( is_mod: bool, ) -> Cow<'static, str> { let abi = match ext { - ast::Extern::None => abi::Abi::Rust, - ast::Extern::Implicit => abi::Abi::C, - ast::Extern::Explicit(abi) => { - abi::lookup(&abi.symbol_unescaped.as_str()).unwrap_or(abi::Abi::Rust) - } + ast::Extern::None => "Rust".to_owned(), + ast::Extern::Implicit => "C".to_owned(), + ast::Extern::Explicit(abi) => abi.symbol_unescaped.to_string(), }; - if abi == abi::Abi::Rust && !is_mod { + if abi == "Rust" && !is_mod { Cow::from("") - } else if abi == abi::Abi::C && !explicit_abi { + } else if abi == "C" && !explicit_abi { Cow::from("extern ") } else { - Cow::from(format!("extern {} ", abi)) + Cow::from(format!(r#"extern "{}" "#, abi)) } } diff --git a/rustfmt-core/rustfmt-lib/tests/source/issue_4086.rs b/rustfmt-core/rustfmt-lib/tests/source/issue_4086.rs new file mode 100644 index 00000000000..ffa6442e930 --- /dev/null +++ b/rustfmt-core/rustfmt-lib/tests/source/issue_4086.rs @@ -0,0 +1,2 @@ +#[cfg(any())] +extern "C++" {} diff --git a/rustfmt-core/rustfmt-lib/tests/target/issue_4086.rs b/rustfmt-core/rustfmt-lib/tests/target/issue_4086.rs new file mode 100644 index 00000000000..959d3b3d468 --- /dev/null +++ b/rustfmt-core/rustfmt-lib/tests/target/issue_4086.rs @@ -0,0 +1,2 @@ +#[cfg(any())] +extern "C++" {} From 3c7fc6ee37c29cf7848a9e91ce70ce828722fd3c Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Thu, 19 Mar 2020 21:52:06 -0500 Subject: [PATCH 2/2] deps: remove unneeded rustc-ap-rustc_target --- Cargo.lock | 1 - rustfmt-core/rustfmt-lib/Cargo.toml | 4 ---- rustfmt-core/rustfmt-lib/src/utils.rs | 1 - 3 files changed, 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 042eefb7aa3..b909e5949ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1062,7 +1062,6 @@ dependencies = [ "rustc-ap-rustc_parse", "rustc-ap-rustc_session", "rustc-ap-rustc_span", - "rustc-ap-rustc_target", "rustc-ap-syntax", "rustfmt_configuration", "rustfmt_emitter", diff --git a/rustfmt-core/rustfmt-lib/Cargo.toml b/rustfmt-core/rustfmt-lib/Cargo.toml index 2e292424af9..7ce58421738 100644 --- a/rustfmt-core/rustfmt-lib/Cargo.toml +++ b/rustfmt-core/rustfmt-lib/Cargo.toml @@ -54,10 +54,6 @@ version = "642.0.0" package = "rustc-ap-rustc_span" version = "642.0.0" -[dependencies.rustc_target] -package = "rustc-ap-rustc_target" -version = "642.0.0" - [dependencies.syntax] package = "rustc-ap-syntax" version = "642.0.0" diff --git a/rustfmt-core/rustfmt-lib/src/utils.rs b/rustfmt-core/rustfmt-lib/src/utils.rs index 1c02e05b66c..63bbbbd4952 100644 --- a/rustfmt-core/rustfmt-lib/src/utils.rs +++ b/rustfmt-core/rustfmt-lib/src/utils.rs @@ -2,7 +2,6 @@ use std::borrow::Cow; use rustc_ast_pretty::pprust; use rustc_span::{sym, BytePos, ExpnId, Span, Symbol, SyntaxContext}; -use rustc_target::spec::abi; use syntax::ast::{ self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility, VisibilityKind,