Skip to content

Commit c126730

Browse files
fix: formatting arbitrary extern abi (#4089)
1 parent 00e199c commit c126730

File tree

5 files changed

+12
-16
lines changed

5 files changed

+12
-16
lines changed

Cargo.lock

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

Cargo.toml

+1-5
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 <ncameron@mozilla.com>", "The Rustfmt developers"]
66
description = "Tool to find and fix Rust formatting issues"
77
repository = "https://github.com/rust-lang/rustfmt"
@@ -94,7 +94,3 @@ version = "651.0.0"
9494
[dependencies.rustc_span]
9595
package = "rustc-ap-rustc_span"
9696
version = "651.0.0"
97-
98-
[dependencies.rustc_target]
99-
package = "rustc-ap-rustc_target"
100-
version = "651.0.0"

src/utils.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_ast::ast::{
77
use rustc_ast::ptr;
88
use rustc_ast_pretty::pprust;
99
use rustc_span::{sym, BytePos, ExpnId, Span, Symbol, SyntaxContext};
10-
use rustc_target::spec::abi;
1110
use unicode_width::UnicodeWidthStr;
1211

1312
use crate::comment::{filter_normal_code, CharClasses, FullCodeCharKind, LineClasses};
@@ -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

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

tests/target/issue_4086.rs

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

0 commit comments

Comments
 (0)