Skip to content

Commit 5d7c093

Browse files
compiler: remove abi-specific extern "{abi}" suggestions
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 c00cf99 commit 5d7c093

9 files changed

+14
-69
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::{
@@ -1482,8 +1481,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
14821481

14831482
pub(super) fn lower_abi(&mut self, abi_str: StrLit) -> ExternAbi {
14841483
let ast::StrLit { symbol_unescaped, span, .. } = abi_str;
1485-
let extern_abi = rustc_abi::lookup(symbol_unescaped.as_str()).unwrap_or_else(|err| {
1486-
self.error_on_invalid_abi(abi_str, err);
1484+
let extern_abi = rustc_abi::lookup(symbol_unescaped.as_str()).unwrap_or_else(|_| {
1485+
self.error_on_invalid_abi(abi_str);
14871486
ExternAbi::Rust
14881487
});
14891488
let sess = self.tcx.sess;
@@ -1500,7 +1499,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15001499
}
15011500
}
15021501

1503-
fn error_on_invalid_abi(&self, abi: StrLit, err: rustc_abi::AbiUnsupported) {
1502+
fn error_on_invalid_abi(&self, abi: StrLit) {
15041503
let abi_names = enabled_names(self.tcx.features(), abi.span)
15051504
.iter()
15061505
.map(|s| Symbol::intern(s))
@@ -1509,10 +1508,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
15091508
self.dcx().emit_err(InvalidAbi {
15101509
abi: abi.symbol_unescaped,
15111510
span: abi.span,
1512-
explain: match err {
1513-
rustc_abi::AbiUnsupported::Reason { explain } => Some(InvalidAbiReason(explain)),
1514-
_ => None,
1515-
},
15161511
suggestion: suggested_name.map(|suggested_name| InvalidAbiSuggestion {
15171512
span: abi.span,
15181513
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

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ LL | extern "riscv-interrupt" fn isr() {}
88
| help: did you mean: `"riscv-interrupt-m"`
99
|
1010
= note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
11-
= note: please use one of riscv-interrupt-m or riscv-interrupt-s for machine- or supervisor-level interrupts, respectively
1211

1312
error[E0703]: invalid ABI: found `riscv-interrupt-u`
14-
--> $DIR/riscv-discoverability-guidance.rs:23:8
13+
--> $DIR/riscv-discoverability-guidance.rs:22:8
1514
|
1615
LL | extern "riscv-interrupt-u" fn isr_U() {}
1716
| ^^^^^^^^^^^^^^^^^^^
@@ -20,7 +19,6 @@ LL | extern "riscv-interrupt-u" fn isr_U() {}
2019
| help: did you mean: `"riscv-interrupt-m"`
2120
|
2221
= note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
23-
= note: user-mode interrupt handlers have been removed from LLVM pending standardization, see: https://reviews.llvm.org/D149314
2422

2523
error: aborting due to 2 previous errors
2624

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ LL | extern "riscv-interrupt" fn isr() {}
88
| help: did you mean: `"riscv-interrupt-m"`
99
|
1010
= note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
11-
= note: please use one of riscv-interrupt-m or riscv-interrupt-s for machine- or supervisor-level interrupts, respectively
1211

1312
error[E0703]: invalid ABI: found `riscv-interrupt-u`
14-
--> $DIR/riscv-discoverability-guidance.rs:23:8
13+
--> $DIR/riscv-discoverability-guidance.rs:22:8
1514
|
1615
LL | extern "riscv-interrupt-u" fn isr_U() {}
1716
| ^^^^^^^^^^^^^^^^^^^
@@ -20,7 +19,6 @@ LL | extern "riscv-interrupt-u" fn isr_U() {}
2019
| help: did you mean: `"riscv-interrupt-m"`
2120
|
2221
= note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
23-
= note: user-mode interrupt handlers have been removed from LLVM pending standardization, see: https://reviews.llvm.org/D149314
2422

2523
error: aborting due to 2 previous errors
2624

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

-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ extern "riscv-interrupt" fn isr() {}
1818
//~^ ERROR invalid ABI
1919
//~^^ NOTE invalid ABI
2020
//~^^^ NOTE invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
21-
//~^^^^ NOTE please use one of riscv-interrupt-m or riscv-interrupt-s
2221

2322
extern "riscv-interrupt-u" fn isr_U() {}
2423
//~^ ERROR invalid ABI
2524
//~^^ NOTE invalid ABI
2625
//~^^^ NOTE invoke `rustc --print=calling-conventions` for a full list of supported calling conventions
27-
//~^^^^ NOTE user-mode interrupt handlers have been removed from LLVM pending standardization

0 commit comments

Comments
 (0)