diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index 051753715913a..53953b089c613 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -367,9 +367,7 @@ fn push_debuginfo_type_name<'tcx>( output.push_str(sig.safety.prefix_str()); if sig.abi != rustc_abi::ExternAbi::Rust { - output.push_str("extern \""); - output.push_str(sig.abi.name()); - output.push_str("\" "); + let _ = write!(output, "extern {} ", sig.abi); } output.push_str("fn("); diff --git a/compiler/rustc_errors/src/diagnostic_impls.rs b/compiler/rustc_errors/src/diagnostic_impls.rs index 14baf7554bcf6..7f383946c1463 100644 --- a/compiler/rustc_errors/src/diagnostic_impls.rs +++ b/compiler/rustc_errors/src/diagnostic_impls.rs @@ -93,6 +93,7 @@ into_diag_arg_using_display!( SplitDebuginfo, ExitStatus, ErrCode, + rustc_abi::ExternAbi, ); impl IntoDiagArg for rustc_type_ir::TraitRef { diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl index be731547b31b6..7344ea01fb214 100644 --- a/compiler/rustc_hir_analysis/messages.ftl +++ b/compiler/rustc_hir_analysis/messages.ftl @@ -72,17 +72,17 @@ hir_analysis_cmse_entry_generic = functions with the `"C-cmse-nonsecure-entry"` ABI cannot contain generics in their type hir_analysis_cmse_inputs_stack_spill = - arguments for `"{$abi_name}"` function too large to pass via registers + arguments for `{$abi}` function too large to pass via registers .label = {$plural -> [false] this argument doesn't *[true] these arguments don't } fit in the available registers - .note = functions with the `"{$abi_name}"` ABI must pass all their arguments via the 4 32-bit available argument registers + .note = functions with the `{$abi}` ABI must pass all their arguments via the 4 32-bit available argument registers hir_analysis_cmse_output_stack_spill = - return value of `"{$abi_name}"` function too large to pass via registers + return value of `{$abi}` function too large to pass via registers .label = this type doesn't fit in the available registers - .note1 = functions with the `"{$abi_name}"` ABI must pass their result via the available return registers + .note1 = functions with the `{$abi}` ABI must pass their result via the available return registers .note2 = the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size hir_analysis_coerce_pointee_no_field = `CoercePointee` can only be derived on `struct`s with at least one field diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index e1e6b677c0061..1574506de603b 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -1,5 +1,6 @@ //! Errors emitted by `rustc_hir_analysis`. +use rustc_abi::ExternAbi; use rustc_errors::codes::*; use rustc_errors::{ Applicability, Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, MultiSpan, @@ -1690,7 +1691,7 @@ pub(crate) struct CmseInputsStackSpill { #[label] pub span: Span, pub plural: bool, - pub abi_name: &'static str, + pub abi: ExternAbi, } #[derive(Diagnostic)] @@ -1701,7 +1702,7 @@ pub(crate) struct CmseOutputStackSpill { #[primary_span] #[label] pub span: Span, - pub abi_name: &'static str, + pub abi: ExternAbi, } #[derive(Diagnostic)] diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs index 4c8f2735b9795..5fed2e352879c 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs @@ -17,8 +17,6 @@ pub(crate) fn validate_cmse_abi<'tcx>( abi: ExternAbi, fn_sig: ty::PolyFnSig<'tcx>, ) { - let abi_name = abi.name(); - match abi { ExternAbi::CCmseNonSecureCall => { let hir_node = tcx.hir_node(hir_id); @@ -56,7 +54,7 @@ pub(crate) fn validate_cmse_abi<'tcx>( .to(bare_fn_ty.decl.inputs[index].span) .to(bare_fn_ty.decl.inputs.last().unwrap().span); let plural = bare_fn_ty.param_names.len() - index != 1; - dcx.emit_err(errors::CmseInputsStackSpill { span, plural, abi_name }); + dcx.emit_err(errors::CmseInputsStackSpill { span, plural, abi }); } Err(layout_err) => { if should_emit_generic_error(abi, layout_err) { @@ -69,7 +67,7 @@ pub(crate) fn validate_cmse_abi<'tcx>( Ok(true) => {} Ok(false) => { let span = bare_fn_ty.decl.output.span(); - dcx.emit_err(errors::CmseOutputStackSpill { span, abi_name }); + dcx.emit_err(errors::CmseOutputStackSpill { span, abi }); } Err(layout_err) => { if should_emit_generic_error(abi, layout_err) { @@ -92,7 +90,7 @@ pub(crate) fn validate_cmse_abi<'tcx>( // ^^^^^^ let span = decl.inputs[index].span.to(decl.inputs.last().unwrap().span); let plural = decl.inputs.len() - index != 1; - dcx.emit_err(errors::CmseInputsStackSpill { span, plural, abi_name }); + dcx.emit_err(errors::CmseInputsStackSpill { span, plural, abi }); } Err(layout_err) => { if should_emit_generic_error(abi, layout_err) { @@ -105,7 +103,7 @@ pub(crate) fn validate_cmse_abi<'tcx>( Ok(true) => {} Ok(false) => { let span = decl.output.span(); - dcx.emit_err(errors::CmseOutputStackSpill { span, abi_name }); + dcx.emit_err(errors::CmseOutputStackSpill { span, abi }); } Err(layout_err) => { if should_emit_generic_error(abi, layout_err) { diff --git a/compiler/rustc_lint/src/early/diagnostics.rs b/compiler/rustc_lint/src/early/diagnostics.rs index 92dbc76a7b5ec..aeb5a03a4f7e3 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -160,8 +160,7 @@ pub(super) fn decorate_lint( .decorate_lint(diag); } BuiltinLintDiag::MissingAbi(label_span, default_abi) => { - lints::MissingAbi { span: label_span, default_abi: default_abi.name() } - .decorate_lint(diag); + lints::MissingAbi { span: label_span, default_abi }.decorate_lint(diag); } BuiltinLintDiag::LegacyDeriveHelpers(label_span) => { lints::LegacyDeriveHelpers { span: label_span }.decorate_lint(diag); diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 09b0e1ed8bdba..368d36bfdd0b2 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -2,6 +2,7 @@ #![allow(rustc::untranslatable_diagnostic)] use std::num::NonZero; +use rustc_abi::ExternAbi; use rustc_errors::codes::*; use rustc_errors::{ Applicability, Diag, DiagArgValue, DiagMessage, DiagStyledString, ElidedLifetimeInPathSubdiag, @@ -2833,9 +2834,9 @@ pub(crate) struct PatternsInFnsWithoutBodySub { #[derive(LintDiagnostic)] #[diag(lint_extern_without_abi)] pub(crate) struct MissingAbi { - #[suggestion(code = "extern \"{default_abi}\"", applicability = "machine-applicable")] + #[suggestion(code = "extern {default_abi}", applicability = "machine-applicable")] pub span: Span, - pub default_abi: &'static str, + pub default_abi: ExternAbi, } #[derive(LintDiagnostic)] diff --git a/compiler/rustc_mir_transform/src/function_item_references.rs b/compiler/rustc_mir_transform/src/function_item_references.rs index 7e88925b2e1b6..73e47bb79f0bf 100644 --- a/compiler/rustc_mir_transform/src/function_item_references.rs +++ b/compiler/rustc_mir_transform/src/function_item_references.rs @@ -161,12 +161,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> { let unsafety = fn_sig.safety().prefix_str(); let abi = match fn_sig.abi() { ExternAbi::Rust => String::from(""), - other_abi => { - let mut s = String::from("extern \""); - s.push_str(other_abi.name()); - s.push_str("\" "); - s - } + other_abi => format!("extern {other_abi} "), }; let ident = self.tcx.item_ident(fn_id); let ty_params = fn_args.types().map(|ty| format!("{ty}")); diff --git a/tests/ui/link-native-libs/suggest-libname-only-1.stderr b/tests/ui/link-native-libs/suggest-libname-only-1.stderr index aae8f7de966a0..47f7d92c9f9e2 100644 --- a/tests/ui/link-native-libs/suggest-libname-only-1.stderr +++ b/tests/ui/link-native-libs/suggest-libname-only-1.stderr @@ -2,7 +2,7 @@ warning: extern declarations without an explicit ABI are deprecated --> $DIR/suggest-libname-only-1.rs:7:1 | LL | extern { } - | ^^^^^^ help: explicitly specify the C ABI: `extern "C"` + | ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` | = note: `#[warn(missing_abi)]` on by default diff --git a/tests/ui/link-native-libs/suggest-libname-only-2.stderr b/tests/ui/link-native-libs/suggest-libname-only-2.stderr index a2adaee3f97f5..a2d8f4c8191bf 100644 --- a/tests/ui/link-native-libs/suggest-libname-only-2.stderr +++ b/tests/ui/link-native-libs/suggest-libname-only-2.stderr @@ -2,7 +2,7 @@ warning: extern declarations without an explicit ABI are deprecated --> $DIR/suggest-libname-only-2.rs:7:1 | LL | extern { } - | ^^^^^^ help: explicitly specify the C ABI: `extern "C"` + | ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` | = note: `#[warn(missing_abi)]` on by default diff --git a/tests/ui/lint/cli-lint-override.forbid_warn.stderr b/tests/ui/lint/cli-lint-override.forbid_warn.stderr index 169be997b48c6..fb8779ad4f15d 100644 --- a/tests/ui/lint/cli-lint-override.forbid_warn.stderr +++ b/tests/ui/lint/cli-lint-override.forbid_warn.stderr @@ -2,7 +2,7 @@ error: extern declarations without an explicit ABI are deprecated --> $DIR/cli-lint-override.rs:12:1 | LL | extern fn foo() {} - | ^^^^^^ help: explicitly specify the C ABI: `extern "C"` + | ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` | = note: requested on the command line with `-F missing-abi` diff --git a/tests/ui/lint/cli-lint-override.force_warn_deny.stderr b/tests/ui/lint/cli-lint-override.force_warn_deny.stderr index 574f2ca66a420..10fc13e3f52f8 100644 --- a/tests/ui/lint/cli-lint-override.force_warn_deny.stderr +++ b/tests/ui/lint/cli-lint-override.force_warn_deny.stderr @@ -2,7 +2,7 @@ warning: extern declarations without an explicit ABI are deprecated --> $DIR/cli-lint-override.rs:12:1 | LL | extern fn foo() {} - | ^^^^^^ help: explicitly specify the C ABI: `extern "C"` + | ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` | = note: requested on the command line with `--force-warn missing-abi` diff --git a/tests/ui/lint/cli-lint-override.warn_deny.stderr b/tests/ui/lint/cli-lint-override.warn_deny.stderr index bfec37ada95e5..979ca22324f1e 100644 --- a/tests/ui/lint/cli-lint-override.warn_deny.stderr +++ b/tests/ui/lint/cli-lint-override.warn_deny.stderr @@ -2,7 +2,7 @@ error: extern declarations without an explicit ABI are deprecated --> $DIR/cli-lint-override.rs:12:1 | LL | extern fn foo() {} - | ^^^^^^ help: explicitly specify the C ABI: `extern "C"` + | ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` | = note: requested on the command line with `-D missing-abi` diff --git a/tests/ui/parser/bad-lit-suffixes.stderr b/tests/ui/parser/bad-lit-suffixes.stderr index 704f7363e81c2..d6b50b0e0d1fe 100644 --- a/tests/ui/parser/bad-lit-suffixes.stderr +++ b/tests/ui/parser/bad-lit-suffixes.stderr @@ -55,7 +55,7 @@ warning: extern declarations without an explicit ABI are deprecated --> $DIR/bad-lit-suffixes.rs:3:1 | LL | extern - | ^^^^^^ help: explicitly specify the C ABI: `extern "C"` + | ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` | = note: `#[warn(missing_abi)]` on by default @@ -63,7 +63,7 @@ warning: extern declarations without an explicit ABI are deprecated --> $DIR/bad-lit-suffixes.rs:7:1 | LL | extern - | ^^^^^^ help: explicitly specify the C ABI: `extern "C"` + | ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` error: suffixes on string literals are invalid --> $DIR/bad-lit-suffixes.rs:12:5 diff --git a/tests/ui/parser/lit-err-in-macro.stderr b/tests/ui/parser/lit-err-in-macro.stderr index fc2603d0b104c..9422f22f9c8fe 100644 --- a/tests/ui/parser/lit-err-in-macro.stderr +++ b/tests/ui/parser/lit-err-in-macro.stderr @@ -8,7 +8,7 @@ warning: extern declarations without an explicit ABI are deprecated --> $DIR/lit-err-in-macro.rs:3:9 | LL | extern $abi fn f() {} - | ^^^^^^ help: explicitly specify the C ABI: `extern "C"` + | ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` ... LL | f!("Foo"__); | ----------- in this macro invocation diff --git a/tests/ui/proc-macro/inner-attrs.stderr b/tests/ui/proc-macro/inner-attrs.stderr index 3ab180be821a9..8b5fec1b4c37e 100644 --- a/tests/ui/proc-macro/inner-attrs.stderr +++ b/tests/ui/proc-macro/inner-attrs.stderr @@ -26,7 +26,7 @@ warning: extern declarations without an explicit ABI are deprecated --> $DIR/inner-attrs.rs:82:1 | LL | extern { - | ^^^^^^ help: explicitly specify the C ABI: `extern "C"` + | ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` | = note: `#[warn(missing_abi)]` on by default