Skip to content

Commit 0899916

Browse files
fix: formatting arbitrary extern abi
1 parent 5ca3d02 commit 0899916

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "rustfmt-nightly"
4-
version = "1.4.12"
4+
version = "1.4.13"
55
authors = ["Nicholas Cameron <ncameron@mozilla.com>", "The Rustfmt developers"]
66
description = "Tool to find and fix Rust formatting issues"
77
repository = "https://github.com/rust-lang/rustfmt"

src/utils.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,17 @@ pub(crate) fn format_extern(
140140
is_mod: bool,
141141
) -> Cow<'static, str> {
142142
let abi = match ext {
143-
ast::Extern::None => abi::Abi::Rust,
144-
ast::Extern::Implicit => abi::Abi::C,
145-
ast::Extern::Explicit(abi) => {
146-
abi::lookup(&abi.symbol_unescaped.as_str()).unwrap_or(abi::Abi::Rust)
147-
}
143+
ast::Extern::None => "Rust".to_owned(),
144+
ast::Extern::Implicit => "C".to_owned(),
145+
ast::Extern::Explicit(abi) => abi.symbol_unescaped.to_string(),
148146
};
149147

150-
if abi == abi::Abi::Rust && !is_mod {
148+
if abi == "Rust" && !is_mod {
151149
Cow::from("")
152-
} else if abi == abi::Abi::C && !explicit_abi {
150+
} else if abi == "C" && !explicit_abi {
153151
Cow::from("extern ")
154152
} else {
155-
Cow::from(format!("extern {} ", abi))
153+
Cow::from(format!(r#"extern "{}" "#, abi))
156154
}
157155
}
158156

tests/source/issue_4086.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#[cfg(any())]
2+
extern "C++" {}

tests/target/issue_4086.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#[cfg(any())]
2+
extern "C++" {}

0 commit comments

Comments
 (0)