Skip to content

Commit 267e8c2

Browse files
committed
maintain force_explicit_abi = false behavior
1 parent 59fdfaf commit 267e8c2

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/utils.rs

+4
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ pub(crate) fn format_extern(ext: ast::Extern, explicit_abi: bool) -> Cow<'static
136136
ast::Extern::None => Cow::from(""),
137137
ast::Extern::Implicit(_) if explicit_abi => Cow::from("extern \"C\" "),
138138
ast::Extern::Implicit(_) => Cow::from("extern "),
139+
// turn `extern "C"` into `extern` when `explicit_abi` is set to false
140+
ast::Extern::Explicit(abi, _) if abi.symbol_unescaped == sym::C && !explicit_abi => {
141+
Cow::from("extern ")
142+
}
139143
ast::Extern::Explicit(abi, _) => {
140144
Cow::from(format!(r#"extern "{}" "#, abi.symbol_unescaped))
141145
}

tests/target/extern_not_explicit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// rustfmt-force_explicit_abi: false
22

3-
extern "C" {
3+
extern {
44
fn some_fn() -> ();
55
}
66

7-
extern "C" fn sup() {}
7+
extern fn sup() {}
88

9-
type funky_func = extern "C" fn(
9+
type funky_func = extern fn(
1010
unsafe extern "rust-call" fn(
1111
*const JSJitInfo,
1212
*mut JSContext,

0 commit comments

Comments
 (0)