diff --git a/src/utils.rs b/src/utils.rs index 940dffc6da6..070bd81721f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -136,6 +136,10 @@ pub(crate) fn format_extern(ext: ast::Extern, explicit_abi: bool) -> Cow<'static ast::Extern::None => Cow::from(""), ast::Extern::Implicit(_) if explicit_abi => Cow::from("extern \"C\" "), ast::Extern::Implicit(_) => Cow::from("extern "), + // turn `extern "C"` into `extern` when `force_explicit_abi` is set to false + ast::Extern::Explicit(abi, _) if abi.symbol_unescaped == sym::C && !force_explicit_abi => { + Cow::from("extern ") + } ast::Extern::Explicit(abi, _) => { Cow::from(format!(r#"extern "{}" "#, abi.symbol_unescaped)) } diff --git a/tests/target/extern_not_explicit.rs b/tests/target/extern_not_explicit.rs index 1f800cf1460..b55b64d05b3 100644 --- a/tests/target/extern_not_explicit.rs +++ b/tests/target/extern_not_explicit.rs @@ -1,12 +1,12 @@ // rustfmt-force_explicit_abi: false -extern "C" { +extern { fn some_fn() -> (); } -extern "C" fn sup() {} +extern fn sup() {} -type funky_func = extern "C" fn( +type funky_func = extern fn( unsafe extern "rust-call" fn( *const JSJitInfo, *mut JSContext,