Skip to content

compiler: replace ExternAbi::name calls with formatters #136900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(");
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_errors/src/diagnostic_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ into_diag_arg_using_display!(
SplitDebuginfo,
ExitStatus,
ErrCode,
rustc_abi::ExternAbi,
);

impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::TraitRef<I> {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -1689,7 +1690,7 @@ pub(crate) struct CmseInputsStackSpill {
#[label]
pub span: Span,
pub plural: bool,
pub abi_name: &'static str,
pub abi: ExternAbi,
}

#[derive(Diagnostic)]
Expand All @@ -1700,7 +1701,7 @@ pub(crate) struct CmseOutputStackSpill {
#[primary_span]
#[label]
pub span: Span,
pub abi_name: &'static str,
pub abi: ExternAbi,
}

#[derive(Diagnostic)]
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_lint/src/early/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)]
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_mir_transform/src/function_item_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"));
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/link-native-libs/suggest-libname-only-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/link-native-libs/suggest-libname-only-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/lint/cli-lint-override.forbid_warn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/lint/cli-lint-override.force_warn_deny.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/lint/cli-lint-override.warn_deny.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/parser/bad-lit-suffixes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ 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

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
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/parser/lit-err-in-macro.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/inner-attrs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading