diff --git a/compiler/rustc_abi/src/extern_abi.rs b/compiler/rustc_abi/src/extern_abi.rs index faa952b6e2cfe..f3cf7f583cebd 100644 --- a/compiler/rustc_abi/src/extern_abi.rs +++ b/compiler/rustc_abi/src/extern_abi.rs @@ -141,27 +141,14 @@ pub const AbiDatas: &[AbiData] = &[ ]; #[derive(Copy, Clone, Debug)] -pub enum AbiUnsupported { - Unrecognized, - Reason { explain: &'static str }, -} - +pub struct AbiUnsupported {} /// Returns the ABI with the given name (if any). pub fn lookup(name: &str) -> Result { - AbiDatas.iter().find(|abi_data| name == abi_data.name).map(|&x| x.abi).ok_or_else(|| match name { - "riscv-interrupt" => AbiUnsupported::Reason { - explain: "please use one of riscv-interrupt-m or riscv-interrupt-s for machine- or supervisor-level interrupts, respectively", - }, - "riscv-interrupt-u" => AbiUnsupported::Reason { - explain: "user-mode interrupt handlers have been removed from LLVM pending standardization, see: https://reviews.llvm.org/D149314", - }, - "wasm" => AbiUnsupported::Reason { - explain: "non-standard wasm ABI is no longer supported", - }, - - _ => AbiUnsupported::Unrecognized, - - }) + AbiDatas + .iter() + .find(|abi_data| name == abi_data.name) + .map(|&x| x.abi) + .ok_or_else(|| AbiUnsupported {}) } pub fn all_names() -> Vec<&'static str> { diff --git a/compiler/rustc_abi/src/extern_abi/tests.rs b/compiler/rustc_abi/src/extern_abi/tests.rs index 4823058dd6970..72c0f183d50c1 100644 --- a/compiler/rustc_abi/src/extern_abi/tests.rs +++ b/compiler/rustc_abi/src/extern_abi/tests.rs @@ -18,7 +18,7 @@ fn lookup_cdecl() { #[test] fn lookup_baz() { let abi = lookup("baz"); - assert_matches!(abi, Err(AbiUnsupported::Unrecognized)); + assert_matches!(abi, Err(AbiUnsupported {})); } #[test] diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index f727691bf479c..9f69387b7b715 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -1,5 +1,5 @@ +use rustc_errors::DiagArgFromDisplay; use rustc_errors::codes::*; -use rustc_errors::{Diag, DiagArgFromDisplay, EmissionGuarantee, SubdiagMessageOp, Subdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::{Ident, Span, Symbol}; @@ -32,8 +32,6 @@ pub(crate) struct InvalidAbi { pub abi: Symbol, pub command: String, #[subdiagnostic] - pub explain: Option, - #[subdiagnostic] pub suggestion: Option, } @@ -45,19 +43,6 @@ pub(crate) struct TupleStructWithDefault { pub span: Span, } -pub(crate) struct InvalidAbiReason(pub &'static str); - -impl Subdiagnostic for InvalidAbiReason { - fn add_to_diag_with>( - self, - diag: &mut Diag<'_, G>, - _: &F, - ) { - #[allow(rustc::untranslatable_diagnostic)] - diag.note(self.0); - } -} - #[derive(Subdiagnostic)] #[suggestion( ast_lowering_invalid_abi_suggestion, diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 295be9430aff6..d92a1237f47c9 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -17,8 +17,7 @@ use thin_vec::ThinVec; use tracing::instrument; use super::errors::{ - InvalidAbi, InvalidAbiReason, InvalidAbiSuggestion, MisplacedRelaxTraitBound, - TupleStructWithDefault, + InvalidAbi, InvalidAbiSuggestion, MisplacedRelaxTraitBound, TupleStructWithDefault, }; use super::stability::{enabled_names, gate_unstable_abi}; use super::{ @@ -1473,8 +1472,8 @@ impl<'hir> LoweringContext<'_, 'hir> { pub(super) fn lower_abi(&mut self, abi_str: StrLit) -> ExternAbi { let ast::StrLit { symbol_unescaped, span, .. } = abi_str; - let extern_abi = rustc_abi::lookup(symbol_unescaped.as_str()).unwrap_or_else(|err| { - self.error_on_invalid_abi(abi_str, err); + let extern_abi = rustc_abi::lookup(symbol_unescaped.as_str()).unwrap_or_else(|_| { + self.error_on_invalid_abi(abi_str); ExternAbi::Rust }); let sess = self.tcx.sess; @@ -1491,7 +1490,7 @@ impl<'hir> LoweringContext<'_, 'hir> { } } - fn error_on_invalid_abi(&self, abi: StrLit, err: rustc_abi::AbiUnsupported) { + fn error_on_invalid_abi(&self, abi: StrLit) { let abi_names = enabled_names(self.tcx.features(), abi.span) .iter() .map(|s| Symbol::intern(s)) @@ -1500,10 +1499,6 @@ impl<'hir> LoweringContext<'_, 'hir> { self.dcx().emit_err(InvalidAbi { abi: abi.symbol_unescaped, span: abi.span, - explain: match err { - rustc_abi::AbiUnsupported::Reason { explain } => Some(InvalidAbiReason(explain)), - _ => None, - }, suggestion: suggested_name.map(|suggested_name| InvalidAbiSuggestion { span: abi.span, suggestion: format!("\"{suggested_name}\""), diff --git a/tests/ui/abi/removed-wasm-abi.rs b/tests/ui/abi/removed-wasm-abi.rs deleted file mode 100644 index a45e42bfe020e..0000000000000 --- a/tests/ui/abi/removed-wasm-abi.rs +++ /dev/null @@ -1,4 +0,0 @@ -extern "wasm" fn test() {} -//~^ ERROR invalid ABI: found `wasm` - -fn main() {} diff --git a/tests/ui/abi/removed-wasm-abi.stderr b/tests/ui/abi/removed-wasm-abi.stderr deleted file mode 100644 index 6007c4e258014..0000000000000 --- a/tests/ui/abi/removed-wasm-abi.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0703]: invalid ABI: found `wasm` - --> $DIR/removed-wasm-abi.rs:1:8 - | -LL | extern "wasm" fn test() {} - | ^^^^^^ invalid ABI - | - = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions - = note: non-standard wasm ABI is no longer supported - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0703`. diff --git a/tests/ui/abi/riscv-discoverability-guidance.riscv32.stderr b/tests/ui/abi/riscv-discoverability-guidance.riscv32.stderr deleted file mode 100644 index e80411fda344e..0000000000000 --- a/tests/ui/abi/riscv-discoverability-guidance.riscv32.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error[E0703]: invalid ABI: found `riscv-interrupt` - --> $DIR/riscv-discoverability-guidance.rs:17:8 - | -LL | extern "riscv-interrupt" fn isr() {} - | ^^^^^^^^^^^^^^^^^ - | | - | invalid ABI - | help: did you mean: `"riscv-interrupt-m"` - | - = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions - = note: please use one of riscv-interrupt-m or riscv-interrupt-s for machine- or supervisor-level interrupts, respectively - -error[E0703]: invalid ABI: found `riscv-interrupt-u` - --> $DIR/riscv-discoverability-guidance.rs:23:8 - | -LL | extern "riscv-interrupt-u" fn isr_U() {} - | ^^^^^^^^^^^^^^^^^^^ - | | - | invalid ABI - | help: did you mean: `"riscv-interrupt-m"` - | - = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions - = note: user-mode interrupt handlers have been removed from LLVM pending standardization, see: https://reviews.llvm.org/D149314 - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0703`. diff --git a/tests/ui/abi/riscv-discoverability-guidance.riscv64.stderr b/tests/ui/abi/riscv-discoverability-guidance.riscv64.stderr deleted file mode 100644 index e80411fda344e..0000000000000 --- a/tests/ui/abi/riscv-discoverability-guidance.riscv64.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error[E0703]: invalid ABI: found `riscv-interrupt` - --> $DIR/riscv-discoverability-guidance.rs:17:8 - | -LL | extern "riscv-interrupt" fn isr() {} - | ^^^^^^^^^^^^^^^^^ - | | - | invalid ABI - | help: did you mean: `"riscv-interrupt-m"` - | - = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions - = note: please use one of riscv-interrupt-m or riscv-interrupt-s for machine- or supervisor-level interrupts, respectively - -error[E0703]: invalid ABI: found `riscv-interrupt-u` - --> $DIR/riscv-discoverability-guidance.rs:23:8 - | -LL | extern "riscv-interrupt-u" fn isr_U() {} - | ^^^^^^^^^^^^^^^^^^^ - | | - | invalid ABI - | help: did you mean: `"riscv-interrupt-m"` - | - = note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions - = note: user-mode interrupt handlers have been removed from LLVM pending standardization, see: https://reviews.llvm.org/D149314 - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0703`. diff --git a/tests/ui/abi/riscv-discoverability-guidance.rs b/tests/ui/abi/riscv-discoverability-guidance.rs deleted file mode 100644 index 1b189d907baf6..0000000000000 --- a/tests/ui/abi/riscv-discoverability-guidance.rs +++ /dev/null @@ -1,27 +0,0 @@ -// ignore-tidy-linelength -//@ revisions: riscv32 riscv64 -// -//@ [riscv32] needs-llvm-components: riscv -//@ [riscv32] compile-flags: --target=riscv32i-unknown-none-elf -C target-feature=-unaligned-scalar-mem --crate-type=rlib -//@ [riscv64] needs-llvm-components: riscv -//@ [riscv64] compile-flags: --target=riscv64gc-unknown-none-elf -C target-feature=-unaligned-scalar-mem --crate-type=rlib -#![no_core] -#![feature( - no_core, - lang_items, - abi_riscv_interrupt -)] -#[lang = "sized"] -trait Sized {} - -extern "riscv-interrupt" fn isr() {} -//~^ ERROR invalid ABI -//~^^ NOTE invalid ABI -//~^^^ NOTE invoke `rustc --print=calling-conventions` for a full list of supported calling conventions -//~^^^^ NOTE please use one of riscv-interrupt-m or riscv-interrupt-s - -extern "riscv-interrupt-u" fn isr_U() {} -//~^ ERROR invalid ABI -//~^^ NOTE invalid ABI -//~^^^ NOTE invoke `rustc --print=calling-conventions` for a full list of supported calling conventions -//~^^^^ NOTE user-mode interrupt handlers have been removed from LLVM pending standardization