Skip to content

Commit 4d22687

Browse files
fix formatting arbitrary extern abi (#4088)
* fix: arbitrary abi formatting * deps: remove unneeded rustc-ap-rustc_target
1 parent dee282d commit 4d22687

File tree

5 files changed

+10
-14
lines changed

5 files changed

+10
-14
lines changed

Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rustfmt-core/rustfmt-lib/Cargo.toml

-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ version = "642.0.0"
5454
package = "rustc-ap-rustc_span"
5555
version = "642.0.0"
5656

57-
[dependencies.rustc_target]
58-
package = "rustc-ap-rustc_target"
59-
version = "642.0.0"
60-
6157
[dependencies.syntax]
6258
package = "rustc-ap-syntax"
6359
version = "642.0.0"

rustfmt-core/rustfmt-lib/src/utils.rs

+6-9
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

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

0 commit comments

Comments
 (0)