Skip to content

Commit

Permalink
fix: formatting arbitrary extern abi (#4089)
Browse files Browse the repository at this point in the history
  • Loading branch information
calebcartwright authored Mar 31, 2020
1 parent 00e199c commit c126730
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "rustfmt-nightly"
version = "1.4.12"
version = "1.4.13"
authors = ["Nicholas Cameron <[email protected]>", "The Rustfmt developers"]
description = "Tool to find and fix Rust formatting issues"
repository = "https://github.com/rust-lang/rustfmt"
Expand Down Expand Up @@ -94,7 +94,3 @@ version = "651.0.0"
[dependencies.rustc_span]
package = "rustc-ap-rustc_span"
version = "651.0.0"

[dependencies.rustc_target]
package = "rustc-ap-rustc_target"
version = "651.0.0"
15 changes: 6 additions & 9 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use rustc_ast::ast::{
use rustc_ast::ptr;
use rustc_ast_pretty::pprust;
use rustc_span::{sym, BytePos, ExpnId, Span, Symbol, SyntaxContext};
use rustc_target::spec::abi;
use unicode_width::UnicodeWidthStr;

use crate::comment::{filter_normal_code, CharClasses, FullCodeCharKind, LineClasses};
Expand Down Expand Up @@ -140,19 +139,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))
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/source/issue_4086.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[cfg(any())]
extern "C++" {}
2 changes: 2 additions & 0 deletions tests/target/issue_4086.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[cfg(any())]
extern "C++" {}

0 comments on commit c126730

Please sign in to comment.