Skip to content

Commit c66f564

Browse files
compiler: remove string-specific ABI errors
These are either residue of a long-term migration away from something, or are simply trying too hard to be specifically useful: nearest-match suggestions for ABI strings should handle this.
1 parent 78859ec commit c66f564

9 files changed

+12
-142
lines changed

compiler/rustc_abi/src/extern_abi.rs

+6-19
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,14 @@ pub const AbiDatas: &[AbiData] = &[
141141
];
142142

143143
#[derive(Copy, Clone, Debug)]
144-
pub enum AbiUnsupported {
145-
Unrecognized,
146-
Reason { explain: &'static str },
147-
}
148-
144+
pub struct AbiUnsupported {}
149145
/// Returns the ABI with the given name (if any).
150146
pub fn lookup(name: &str) -> Result<Abi, AbiUnsupported> {
151-
AbiDatas.iter().find(|abi_data| name == abi_data.name).map(|&x| x.abi).ok_or_else(|| match name {
152-
"riscv-interrupt" => AbiUnsupported::Reason {
153-
explain: "please use one of riscv-interrupt-m or riscv-interrupt-s for machine- or supervisor-level interrupts, respectively",
154-
},
155-
"riscv-interrupt-u" => AbiUnsupported::Reason {
156-
explain: "user-mode interrupt handlers have been removed from LLVM pending standardization, see: https://reviews.llvm.org/D149314",
157-
},
158-
"wasm" => AbiUnsupported::Reason {
159-
explain: "non-standard wasm ABI is no longer supported",
160-
},
161-
162-
_ => AbiUnsupported::Unrecognized,
163-
164-
})
147+
AbiDatas
148+
.iter()
149+
.find(|abi_data| name == abi_data.name)
150+
.map(|&x| x.abi)
151+
.ok_or_else(|| AbiUnsupported {})
165152
}
166153

167154
pub fn all_names() -> Vec<&'static str> {

compiler/rustc_abi/src/extern_abi/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn lookup_cdecl() {
1818
#[test]
1919
fn lookup_baz() {
2020
let abi = lookup("baz");
21-
assert_matches!(abi, Err(AbiUnsupported::Unrecognized));
21+
assert_matches!(abi, Err(AbiUnsupported {}));
2222
}
2323

2424
#[test]

compiler/rustc_ast_lowering/src/errors.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use rustc_errors::DiagArgFromDisplay;
12
use rustc_errors::codes::*;
2-
use rustc_errors::{Diag, DiagArgFromDisplay, EmissionGuarantee, SubdiagMessageOp, Subdiagnostic};
33
use rustc_macros::{Diagnostic, Subdiagnostic};
44
use rustc_span::{Ident, Span, Symbol};
55

@@ -32,8 +32,6 @@ pub(crate) struct InvalidAbi {
3232
pub abi: Symbol,
3333
pub command: String,
3434
#[subdiagnostic]
35-
pub explain: Option<InvalidAbiReason>,
36-
#[subdiagnostic]
3735
pub suggestion: Option<InvalidAbiSuggestion>,
3836
}
3937

@@ -45,19 +43,6 @@ pub(crate) struct TupleStructWithDefault {
4543
pub span: Span,
4644
}
4745

48-
pub(crate) struct InvalidAbiReason(pub &'static str);
49-
50-
impl Subdiagnostic for InvalidAbiReason {
51-
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
52-
self,
53-
diag: &mut Diag<'_, G>,
54-
_: &F,
55-
) {
56-
#[allow(rustc::untranslatable_diagnostic)]
57-
diag.note(self.0);
58-
}
59-
}
60-
6146
#[derive(Subdiagnostic)]
6247
#[suggestion(
6348
ast_lowering_invalid_abi_suggestion,

compiler/rustc_ast_lowering/src/item.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ use thin_vec::ThinVec;
1717
use tracing::instrument;
1818

1919
use super::errors::{
20-
InvalidAbi, InvalidAbiReason, InvalidAbiSuggestion, MisplacedRelaxTraitBound,
21-
TupleStructWithDefault,
20+
InvalidAbi, InvalidAbiSuggestion, MisplacedRelaxTraitBound, TupleStructWithDefault,
2221
};
2322
use super::stability::{enabled_names, gate_unstable_abi};
2423
use super::{
@@ -1388,8 +1387,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
13881387

13891388
pub(super) fn lower_abi(&mut self, abi_str: StrLit) -> ExternAbi {
13901389
let ast::StrLit { symbol_unescaped, span, .. } = abi_str;
1391-
let extern_abi = rustc_abi::lookup(symbol_unescaped.as_str()).unwrap_or_else(|err| {
1392-
self.error_on_invalid_abi(abi_str, err);
1390+
let extern_abi = rustc_abi::lookup(symbol_unescaped.as_str()).unwrap_or_else(|_| {
1391+
self.error_on_invalid_abi(abi_str);
13931392
ExternAbi::Rust
13941393
});
13951394
let sess = self.tcx.sess;
@@ -1406,7 +1405,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14061405
}
14071406
}
14081407

1409-
fn error_on_invalid_abi(&self, abi: StrLit, err: rustc_abi::AbiUnsupported) {
1408+
fn error_on_invalid_abi(&self, abi: StrLit) {
14101409
let abi_names = enabled_names(self.tcx.features(), abi.span)
14111410
.iter()
14121411
.map(|s| Symbol::intern(s))
@@ -1415,10 +1414,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
14151414
self.dcx().emit_err(InvalidAbi {
14161415
abi: abi.symbol_unescaped,
14171416
span: abi.span,
1418-
explain: match err {
1419-
rustc_abi::AbiUnsupported::Reason { explain } => Some(InvalidAbiReason(explain)),
1420-
_ => None,
1421-
},
14221417
suggestion: suggested_name.map(|suggested_name| InvalidAbiSuggestion {
14231418
span: abi.span,
14241419
suggestion: format!("\"{suggested_name}\""),

tests/ui/abi/removed-wasm-abi.rs

-4
This file was deleted.

tests/ui/abi/removed-wasm-abi.stderr

-12
This file was deleted.

tests/ui/abi/riscv-discoverability-guidance.riscv32.stderr

-27
This file was deleted.

tests/ui/abi/riscv-discoverability-guidance.riscv64.stderr

-27
This file was deleted.

tests/ui/abi/riscv-discoverability-guidance.rs

-27
This file was deleted.

0 commit comments

Comments
 (0)