Skip to content

Commit

Permalink
maintain force_explicit_abi = false behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
fee1-dead committed Aug 5, 2023
1 parent 825e155 commit 7b089be
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ pub(crate) fn format_extern(ext: ast::Extern, force_explicit_abi: bool) -> Cow<'
ast::Extern::None => Cow::from(""),
ast::Extern::Implicit(_) if force_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))
}
Expand Down
6 changes: 3 additions & 3 deletions tests/target/extern_not_explicit.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 7b089be

Please sign in to comment.