Skip to content

Commit 1316e9f

Browse files
fix: formatting arbitrary extern abi
1 parent 9f53665 commit 1316e9f

File tree

5 files changed

+12
-16
lines changed

5 files changed

+12
-16
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 5 deletions
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 <[email protected]>", "The Rustfmt developers"]
66
description = "Tool to find and fix Rust formatting issues"
77
repository = "https://github.com/rust-lang/rustfmt"
@@ -86,10 +86,6 @@ version = "642.0.0"
8686
package = "rustc-ap-rustc_span"
8787
version = "642.0.0"
8888

89-
[dependencies.rustc_target]
90-
package = "rustc-ap-rustc_target"
91-
version = "642.0.0"
92-
9389
[dependencies.syntax]
9490
package = "rustc-ap-syntax"
9591
version = "642.0.0"

src/utils.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::borrow::Cow;
22

33
use rustc_ast_pretty::pprust;
44
use rustc_span::{sym, BytePos, ExpnId, Span, Symbol, SyntaxContext};
5-
use rustc_target::spec::abi;
65
use syntax::ast::{
76
self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
87
VisibilityKind,
@@ -140,19 +139,17 @@ pub(crate) fn format_extern(
140139
is_mod: bool,
141140
) -> Cow<'static, str> {
142141
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-
}
142+
ast::Extern::None => "Rust".to_owned(),
143+
ast::Extern::Implicit => "C".to_owned(),
144+
ast::Extern::Explicit(abi) => abi.symbol_unescaped.to_string(),
148145
};
149146

150-
if abi == abi::Abi::Rust && !is_mod {
147+
if abi == "Rust" && !is_mod {
151148
Cow::from("")
152-
} else if abi == abi::Abi::C && !explicit_abi {
149+
} else if abi == "C" && !explicit_abi {
153150
Cow::from("extern ")
154151
} else {
155-
Cow::from(format!("extern {} ", abi))
152+
Cow::from(format!(r#"extern "{}" "#, abi))
156153
}
157154
}
158155

tests/source/issue_4086.rs

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

tests/target/issue_4086.rs

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

0 commit comments

Comments
 (0)