Skip to content

Commit 2bd2dea

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 9824774 commit 2bd2dea

9 files changed

+12
-142
lines changed

Diff for: 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> {

Diff for: 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]

Diff for: 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,

Diff for: 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::{
@@ -1473,8 +1472,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
14731472

14741473
pub(super) fn lower_abi(&mut self, abi_str: StrLit) -> ExternAbi {
14751474
let ast::StrLit { symbol_unescaped, span, .. } = abi_str;
1476-
let extern_abi = rustc_abi::lookup(symbol_unescaped.as_str()).unwrap_or_else(|err| {
1477-
self.error_on_invalid_abi(abi_str, err);
1475+
let extern_abi = rustc_abi::lookup(symbol_unescaped.as_str()).unwrap_or_else(|_| {
1476+
self.error_on_invalid_abi(abi_str);
14781477
ExternAbi::Rust
14791478
});
14801479
let sess = self.tcx.sess;
@@ -1491,7 +1490,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14911490
}
14921491
}
14931492

1494-
fn error_on_invalid_abi(&self, abi: StrLit, err: rustc_abi::AbiUnsupported) {
1493+
fn error_on_invalid_abi(&self, abi: StrLit) {
14951494
let abi_names = enabled_names(self.tcx.features(), abi.span)
14961495
.iter()
14971496
.map(|s| Symbol::intern(s))
@@ -1500,10 +1499,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
15001499
self.dcx().emit_err(InvalidAbi {
15011500
abi: abi.symbol_unescaped,
15021501
span: abi.span,
1503-
explain: match err {
1504-
rustc_abi::AbiUnsupported::Reason { explain } => Some(InvalidAbiReason(explain)),
1505-
_ => None,
1506-
},
15071502
suggestion: suggested_name.map(|suggested_name| InvalidAbiSuggestion {
15081503
span: abi.span,
15091504
suggestion: format!("\"{suggested_name}\""),

Diff for: tests/ui/abi/removed-wasm-abi.rs

-4
This file was deleted.

Diff for: tests/ui/abi/removed-wasm-abi.stderr

-12
This file was deleted.

Diff for: tests/ui/abi/riscv-discoverability-guidance.riscv32.stderr

-27
This file was deleted.

Diff for: tests/ui/abi/riscv-discoverability-guidance.riscv64.stderr

-27
This file was deleted.

Diff for: tests/ui/abi/riscv-discoverability-guidance.rs

-27
This file was deleted.

0 commit comments

Comments
 (0)