diff --git a/src/items.rs b/src/items.rs index fd4e08ed403..47cfd124c4d 100644 --- a/src/items.rs +++ b/src/items.rs @@ -248,7 +248,6 @@ impl<'a> Item<'a> { abi: format_extern( ast::Extern::from_abi(fm.abi, DUMMY_SP), config.force_explicit_abi(), - true, ), vis: None, body: fm @@ -336,7 +335,6 @@ impl<'a> FnSig<'a> { result.push_str(&format_extern( self.ext, context.config.force_explicit_abi(), - false, )); result } diff --git a/src/types.rs b/src/types.rs index 18a08f17ba0..54404bee2dd 100644 --- a/src/types.rs +++ b/src/types.rs @@ -896,7 +896,6 @@ fn rewrite_bare_fn( result.push_str(&format_extern( bare_fn.ext, context.config.force_explicit_abi(), - false, )); result.push_str("fn"); diff --git a/src/utils.rs b/src/utils.rs index b8a44d4bade..b01af81276c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -131,23 +131,14 @@ pub(crate) fn format_mutability(mutability: ast::Mutability) -> &'static str { } #[inline] -pub(crate) fn format_extern( - ext: ast::Extern, - explicit_abi: bool, - is_mod: bool, -) -> Cow<'static, str> { - let abi = match ext { - ast::Extern::None => "Rust".to_owned(), - ast::Extern::Implicit(_) => "C".to_owned(), - ast::Extern::Explicit(abi, _) => abi.symbol_unescaped.to_string(), - }; - - if abi == "Rust" && !is_mod { - Cow::from("") - } else if abi == "C" && !explicit_abi { - Cow::from("extern ") - } else { - Cow::from(format!(r#"extern "{}" "#, abi)) +pub(crate) fn format_extern(ext: ast::Extern, force_explicit_abi: bool) -> Cow<'static, str> { + match ext { + ast::Extern::None => Cow::from(""), + ast::Extern::Implicit(_) if force_explicit_abi => Cow::from("extern \"C\" "), + ast::Extern::Implicit(_) => Cow::from("extern "), + ast::Extern::Explicit(abi, _) => { + Cow::from(format!(r#"extern "{}" "#, abi.symbol_unescaped)) + } } } diff --git a/tests/target/extern-rust.rs b/tests/target/extern-rust.rs new file mode 100644 index 00000000000..32824c91203 --- /dev/null +++ b/tests/target/extern-rust.rs @@ -0,0 +1 @@ +extern "Rust" fn uwu() {} diff --git a/tests/target/extern_not_explicit.rs b/tests/target/extern_not_explicit.rs index b55b64d05b3..1f800cf1460 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 { +extern "C" { fn some_fn() -> (); } -extern fn sup() {} +extern "C" fn sup() {} -type funky_func = extern fn( +type funky_func = extern "C" fn( unsafe extern "rust-call" fn( *const JSJitInfo, *mut JSContext,