Skip to content

Commit 32fd1a7

Browse files
compiler: replace ExternAbi::name calls with formatters
Most of these just format the ABI string, so... just format ExternAbi? This makes it more consistent and less jank when we can do it.
1 parent 34a5ea9 commit 32fd1a7

File tree

16 files changed

+27
-34
lines changed

16 files changed

+27
-34
lines changed

Diff for: compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,7 @@ fn push_debuginfo_type_name<'tcx>(
367367
output.push_str(sig.safety.prefix_str());
368368

369369
if sig.abi != rustc_abi::ExternAbi::Rust {
370-
output.push_str("extern \"");
371-
output.push_str(sig.abi.name());
372-
output.push_str("\" ");
370+
let _ = write!(output, "extern {} ", sig.abi);
373371
}
374372

375373
output.push_str("fn(");

Diff for: compiler/rustc_errors/src/diagnostic_impls.rs

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ into_diag_arg_using_display!(
9393
SplitDebuginfo,
9494
ExitStatus,
9595
ErrCode,
96+
rustc_abi::ExternAbi,
9697
);
9798

9899
impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::TraitRef<I> {

Diff for: compiler/rustc_hir_analysis/messages.ftl

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,17 @@ hir_analysis_cmse_entry_generic =
7272
functions with the `"C-cmse-nonsecure-entry"` ABI cannot contain generics in their type
7373
7474
hir_analysis_cmse_inputs_stack_spill =
75-
arguments for `"{$abi_name}"` function too large to pass via registers
75+
arguments for `{$abi}` function too large to pass via registers
7676
.label = {$plural ->
7777
[false] this argument doesn't
7878
*[true] these arguments don't
7979
} fit in the available registers
80-
.note = functions with the `"{$abi_name}"` ABI must pass all their arguments via the 4 32-bit available argument registers
80+
.note = functions with the `{$abi}` ABI must pass all their arguments via the 4 32-bit available argument registers
8181
8282
hir_analysis_cmse_output_stack_spill =
83-
return value of `"{$abi_name}"` function too large to pass via registers
83+
return value of `{$abi}` function too large to pass via registers
8484
.label = this type doesn't fit in the available registers
85-
.note1 = functions with the `"{$abi_name}"` ABI must pass their result via the available return registers
85+
.note1 = functions with the `{$abi}` ABI must pass their result via the available return registers
8686
.note2 = the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size
8787
8888
hir_analysis_coerce_pointee_no_field = `CoercePointee` can only be derived on `struct`s with at least one field

Diff for: compiler/rustc_hir_analysis/src/errors.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Errors emitted by `rustc_hir_analysis`.
22
3+
use rustc_abi::ExternAbi;
34
use rustc_errors::codes::*;
45
use rustc_errors::{
56
Applicability, Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, MultiSpan,
@@ -1689,7 +1690,7 @@ pub(crate) struct CmseInputsStackSpill {
16891690
#[label]
16901691
pub span: Span,
16911692
pub plural: bool,
1692-
pub abi_name: &'static str,
1693+
pub abi: ExternAbi,
16931694
}
16941695

16951696
#[derive(Diagnostic)]
@@ -1700,7 +1701,7 @@ pub(crate) struct CmseOutputStackSpill {
17001701
#[primary_span]
17011702
#[label]
17021703
pub span: Span,
1703-
pub abi_name: &'static str,
1704+
pub abi: ExternAbi,
17041705
}
17051706

17061707
#[derive(Diagnostic)]

Diff for: compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ pub(crate) fn validate_cmse_abi<'tcx>(
1717
abi: ExternAbi,
1818
fn_sig: ty::PolyFnSig<'tcx>,
1919
) {
20-
let abi_name = abi.name();
21-
2220
match abi {
2321
ExternAbi::CCmseNonSecureCall => {
2422
let hir_node = tcx.hir_node(hir_id);
@@ -56,7 +54,7 @@ pub(crate) fn validate_cmse_abi<'tcx>(
5654
.to(bare_fn_ty.decl.inputs[index].span)
5755
.to(bare_fn_ty.decl.inputs.last().unwrap().span);
5856
let plural = bare_fn_ty.param_names.len() - index != 1;
59-
dcx.emit_err(errors::CmseInputsStackSpill { span, plural, abi_name });
57+
dcx.emit_err(errors::CmseInputsStackSpill { span, plural, abi });
6058
}
6159
Err(layout_err) => {
6260
if should_emit_generic_error(abi, layout_err) {
@@ -69,7 +67,7 @@ pub(crate) fn validate_cmse_abi<'tcx>(
6967
Ok(true) => {}
7068
Ok(false) => {
7169
let span = bare_fn_ty.decl.output.span();
72-
dcx.emit_err(errors::CmseOutputStackSpill { span, abi_name });
70+
dcx.emit_err(errors::CmseOutputStackSpill { span, abi });
7371
}
7472
Err(layout_err) => {
7573
if should_emit_generic_error(abi, layout_err) {
@@ -92,7 +90,7 @@ pub(crate) fn validate_cmse_abi<'tcx>(
9290
// ^^^^^^
9391
let span = decl.inputs[index].span.to(decl.inputs.last().unwrap().span);
9492
let plural = decl.inputs.len() - index != 1;
95-
dcx.emit_err(errors::CmseInputsStackSpill { span, plural, abi_name });
93+
dcx.emit_err(errors::CmseInputsStackSpill { span, plural, abi });
9694
}
9795
Err(layout_err) => {
9896
if should_emit_generic_error(abi, layout_err) {
@@ -105,7 +103,7 @@ pub(crate) fn validate_cmse_abi<'tcx>(
105103
Ok(true) => {}
106104
Ok(false) => {
107105
let span = decl.output.span();
108-
dcx.emit_err(errors::CmseOutputStackSpill { span, abi_name });
106+
dcx.emit_err(errors::CmseOutputStackSpill { span, abi });
109107
}
110108
Err(layout_err) => {
111109
if should_emit_generic_error(abi, layout_err) {

Diff for: compiler/rustc_lint/src/early/diagnostics.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ pub(super) fn decorate_lint(
160160
.decorate_lint(diag);
161161
}
162162
BuiltinLintDiag::MissingAbi(label_span, default_abi) => {
163-
lints::MissingAbi { span: label_span, default_abi: default_abi.name() }
164-
.decorate_lint(diag);
163+
lints::MissingAbi { span: label_span, default_abi }.decorate_lint(diag);
165164
}
166165
BuiltinLintDiag::LegacyDeriveHelpers(label_span) => {
167166
lints::LegacyDeriveHelpers { span: label_span }.decorate_lint(diag);

Diff for: compiler/rustc_lint/src/lints.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![allow(rustc::untranslatable_diagnostic)]
33
use std::num::NonZero;
44

5+
use rustc_abi::ExternAbi;
56
use rustc_errors::codes::*;
67
use rustc_errors::{
78
Applicability, Diag, DiagArgValue, DiagMessage, DiagStyledString, ElidedLifetimeInPathSubdiag,
@@ -2833,9 +2834,9 @@ pub(crate) struct PatternsInFnsWithoutBodySub {
28332834
#[derive(LintDiagnostic)]
28342835
#[diag(lint_extern_without_abi)]
28352836
pub(crate) struct MissingAbi {
2836-
#[suggestion(code = "extern \"{default_abi}\"", applicability = "machine-applicable")]
2837+
#[suggestion(code = "extern {default_abi}", applicability = "machine-applicable")]
28372838
pub span: Span,
2838-
pub default_abi: &'static str,
2839+
pub default_abi: ExternAbi,
28392840
}
28402841

28412842
#[derive(LintDiagnostic)]

Diff for: compiler/rustc_mir_transform/src/function_item_references.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
161161
let unsafety = fn_sig.safety().prefix_str();
162162
let abi = match fn_sig.abi() {
163163
ExternAbi::Rust => String::from(""),
164-
other_abi => {
165-
let mut s = String::from("extern \"");
166-
s.push_str(other_abi.name());
167-
s.push_str("\" ");
168-
s
169-
}
164+
other_abi => format!("extern {other_abi} "),
170165
};
171166
let ident = self.tcx.item_ident(fn_id);
172167
let ty_params = fn_args.types().map(|ty| format!("{ty}"));

Diff for: tests/ui/link-native-libs/suggest-libname-only-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ warning: extern declarations without an explicit ABI are deprecated
22
--> $DIR/suggest-libname-only-1.rs:7:1
33
|
44
LL | extern { }
5-
| ^^^^^^ help: explicitly specify the C ABI: `extern "C"`
5+
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"`
66
|
77
= note: `#[warn(missing_abi)]` on by default
88

Diff for: tests/ui/link-native-libs/suggest-libname-only-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ warning: extern declarations without an explicit ABI are deprecated
22
--> $DIR/suggest-libname-only-2.rs:7:1
33
|
44
LL | extern { }
5-
| ^^^^^^ help: explicitly specify the C ABI: `extern "C"`
5+
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"`
66
|
77
= note: `#[warn(missing_abi)]` on by default
88

Diff for: tests/ui/lint/cli-lint-override.forbid_warn.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: extern declarations without an explicit ABI are deprecated
22
--> $DIR/cli-lint-override.rs:12:1
33
|
44
LL | extern fn foo() {}
5-
| ^^^^^^ help: explicitly specify the C ABI: `extern "C"`
5+
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"`
66
|
77
= note: requested on the command line with `-F missing-abi`
88

Diff for: tests/ui/lint/cli-lint-override.force_warn_deny.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ warning: extern declarations without an explicit ABI are deprecated
22
--> $DIR/cli-lint-override.rs:12:1
33
|
44
LL | extern fn foo() {}
5-
| ^^^^^^ help: explicitly specify the C ABI: `extern "C"`
5+
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"`
66
|
77
= note: requested on the command line with `--force-warn missing-abi`
88

Diff for: tests/ui/lint/cli-lint-override.warn_deny.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: extern declarations without an explicit ABI are deprecated
22
--> $DIR/cli-lint-override.rs:12:1
33
|
44
LL | extern fn foo() {}
5-
| ^^^^^^ help: explicitly specify the C ABI: `extern "C"`
5+
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"`
66
|
77
= note: requested on the command line with `-D missing-abi`
88

Diff for: tests/ui/parser/bad-lit-suffixes.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ warning: extern declarations without an explicit ABI are deprecated
5555
--> $DIR/bad-lit-suffixes.rs:3:1
5656
|
5757
LL | extern
58-
| ^^^^^^ help: explicitly specify the C ABI: `extern "C"`
58+
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"`
5959
|
6060
= note: `#[warn(missing_abi)]` on by default
6161

6262
warning: extern declarations without an explicit ABI are deprecated
6363
--> $DIR/bad-lit-suffixes.rs:7:1
6464
|
6565
LL | extern
66-
| ^^^^^^ help: explicitly specify the C ABI: `extern "C"`
66+
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"`
6767

6868
error: suffixes on string literals are invalid
6969
--> $DIR/bad-lit-suffixes.rs:12:5

Diff for: tests/ui/parser/lit-err-in-macro.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ warning: extern declarations without an explicit ABI are deprecated
88
--> $DIR/lit-err-in-macro.rs:3:9
99
|
1010
LL | extern $abi fn f() {}
11-
| ^^^^^^ help: explicitly specify the C ABI: `extern "C"`
11+
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"`
1212
...
1313
LL | f!("Foo"__);
1414
| ----------- in this macro invocation

Diff for: tests/ui/proc-macro/inner-attrs.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ warning: extern declarations without an explicit ABI are deprecated
2626
--> $DIR/inner-attrs.rs:82:1
2727
|
2828
LL | extern {
29-
| ^^^^^^ help: explicitly specify the C ABI: `extern "C"`
29+
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"`
3030
|
3131
= note: `#[warn(missing_abi)]` on by default
3232

0 commit comments

Comments
 (0)