1
Fork 0

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.
This commit is contained in:
Jubilee Young 2025-02-07 12:18:15 -08:00
parent 54ff6e0ad5
commit cd9d39e360
9 changed files with 14 additions and 69 deletions

View file

@ -141,27 +141,14 @@ pub const AbiDatas: &[AbiData] = &[
]; ];
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub enum AbiUnsupported { pub struct AbiUnsupported {}
Unrecognized,
Reason { explain: &'static str },
}
/// Returns the ABI with the given name (if any). /// Returns the ABI with the given name (if any).
pub fn lookup(name: &str) -> Result<Abi, AbiUnsupported> { pub fn lookup(name: &str) -> Result<Abi, AbiUnsupported> {
AbiDatas.iter().find(|abi_data| name == abi_data.name).map(|&x| x.abi).ok_or_else(|| match name { AbiDatas
"riscv-interrupt" => AbiUnsupported::Reason { .iter()
explain: "please use one of riscv-interrupt-m or riscv-interrupt-s for machine- or supervisor-level interrupts, respectively", .find(|abi_data| name == abi_data.name)
}, .map(|&x| x.abi)
"riscv-interrupt-u" => AbiUnsupported::Reason { .ok_or_else(|| AbiUnsupported {})
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,
})
} }
pub fn all_names() -> Vec<&'static str> { pub fn all_names() -> Vec<&'static str> {

View file

@ -18,7 +18,7 @@ fn lookup_cdecl() {
#[test] #[test]
fn lookup_baz() { fn lookup_baz() {
let abi = lookup("baz"); let abi = lookup("baz");
assert_matches!(abi, Err(AbiUnsupported::Unrecognized)); assert_matches!(abi, Err(AbiUnsupported {}));
} }
#[test] #[test]

View file

@ -1,5 +1,5 @@
use rustc_errors::DiagArgFromDisplay;
use rustc_errors::codes::*; use rustc_errors::codes::*;
use rustc_errors::{Diag, DiagArgFromDisplay, EmissionGuarantee, SubdiagMessageOp, Subdiagnostic};
use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic};
use rustc_span::{Ident, Span, Symbol}; use rustc_span::{Ident, Span, Symbol};
@ -32,8 +32,6 @@ pub(crate) struct InvalidAbi {
pub abi: Symbol, pub abi: Symbol,
pub command: String, pub command: String,
#[subdiagnostic] #[subdiagnostic]
pub explain: Option<InvalidAbiReason>,
#[subdiagnostic]
pub suggestion: Option<InvalidAbiSuggestion>, pub suggestion: Option<InvalidAbiSuggestion>,
} }
@ -45,19 +43,6 @@ pub(crate) struct TupleStructWithDefault {
pub span: Span, pub span: Span,
} }
pub(crate) struct InvalidAbiReason(pub &'static str);
impl Subdiagnostic for InvalidAbiReason {
fn add_to_diag_with<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self,
diag: &mut Diag<'_, G>,
_: &F,
) {
#[allow(rustc::untranslatable_diagnostic)]
diag.note(self.0);
}
}
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[suggestion( #[suggestion(
ast_lowering_invalid_abi_suggestion, ast_lowering_invalid_abi_suggestion,

View file

@ -17,8 +17,7 @@ use thin_vec::ThinVec;
use tracing::instrument; use tracing::instrument;
use super::errors::{ use super::errors::{
InvalidAbi, InvalidAbiReason, InvalidAbiSuggestion, MisplacedRelaxTraitBound, InvalidAbi, InvalidAbiSuggestion, MisplacedRelaxTraitBound, TupleStructWithDefault,
TupleStructWithDefault,
}; };
use super::stability::{enabled_names, gate_unstable_abi}; use super::stability::{enabled_names, gate_unstable_abi};
use super::{ use super::{
@ -1482,8 +1481,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
pub(super) fn lower_abi(&mut self, abi_str: StrLit) -> ExternAbi { pub(super) fn lower_abi(&mut self, abi_str: StrLit) -> ExternAbi {
let ast::StrLit { symbol_unescaped, span, .. } = abi_str; let ast::StrLit { symbol_unescaped, span, .. } = abi_str;
let extern_abi = rustc_abi::lookup(symbol_unescaped.as_str()).unwrap_or_else(|err| { let extern_abi = rustc_abi::lookup(symbol_unescaped.as_str()).unwrap_or_else(|_| {
self.error_on_invalid_abi(abi_str, err); self.error_on_invalid_abi(abi_str);
ExternAbi::Rust ExternAbi::Rust
}); });
let sess = self.tcx.sess; let sess = self.tcx.sess;
@ -1500,7 +1499,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) let abi_names = enabled_names(self.tcx.features(), abi.span)
.iter() .iter()
.map(|s| Symbol::intern(s)) .map(|s| Symbol::intern(s))
@ -1509,10 +1508,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.dcx().emit_err(InvalidAbi { self.dcx().emit_err(InvalidAbi {
abi: abi.symbol_unescaped, abi: abi.symbol_unescaped,
span: abi.span, span: abi.span,
explain: match err {
rustc_abi::AbiUnsupported::Reason { explain } => Some(InvalidAbiReason(explain)),
_ => None,
},
suggestion: suggested_name.map(|suggested_name| InvalidAbiSuggestion { suggestion: suggested_name.map(|suggested_name| InvalidAbiSuggestion {
span: abi.span, span: abi.span,
suggestion: format!("\"{suggested_name}\""), suggestion: format!("\"{suggested_name}\""),

View file

@ -1,4 +0,0 @@
extern "wasm" fn test() {}
//~^ ERROR invalid ABI: found `wasm`
fn main() {}

View file

@ -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`.

View file

@ -8,10 +8,9 @@ LL | extern "riscv-interrupt" fn isr() {}
| help: did you mean: `"riscv-interrupt-m"` | help: did you mean: `"riscv-interrupt-m"`
| |
= note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions = 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` error[E0703]: invalid ABI: found `riscv-interrupt-u`
--> $DIR/riscv-discoverability-guidance.rs:23:8 --> $DIR/riscv-discoverability-guidance.rs:22:8
| |
LL | extern "riscv-interrupt-u" fn isr_U() {} LL | extern "riscv-interrupt-u" fn isr_U() {}
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
@ -20,7 +19,6 @@ LL | extern "riscv-interrupt-u" fn isr_U() {}
| help: did you mean: `"riscv-interrupt-m"` | help: did you mean: `"riscv-interrupt-m"`
| |
= note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions = 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 error: aborting due to 2 previous errors

View file

@ -8,10 +8,9 @@ LL | extern "riscv-interrupt" fn isr() {}
| help: did you mean: `"riscv-interrupt-m"` | help: did you mean: `"riscv-interrupt-m"`
| |
= note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions = 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` error[E0703]: invalid ABI: found `riscv-interrupt-u`
--> $DIR/riscv-discoverability-guidance.rs:23:8 --> $DIR/riscv-discoverability-guidance.rs:22:8
| |
LL | extern "riscv-interrupt-u" fn isr_U() {} LL | extern "riscv-interrupt-u" fn isr_U() {}
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
@ -20,7 +19,6 @@ LL | extern "riscv-interrupt-u" fn isr_U() {}
| help: did you mean: `"riscv-interrupt-m"` | help: did you mean: `"riscv-interrupt-m"`
| |
= note: invoke `rustc --print=calling-conventions` for a full list of supported calling conventions = 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 error: aborting due to 2 previous errors

View file

@ -18,10 +18,8 @@ extern "riscv-interrupt" fn isr() {}
//~^ ERROR invalid ABI //~^ ERROR invalid ABI
//~^^ NOTE invalid ABI //~^^ NOTE invalid ABI
//~^^^ NOTE invoke `rustc --print=calling-conventions` for a full list of supported calling conventions //~^^^ 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() {} extern "riscv-interrupt-u" fn isr_U() {}
//~^ ERROR invalid ABI //~^ ERROR invalid ABI
//~^^ NOTE invalid ABI //~^^ NOTE invalid ABI
//~^^^ NOTE invoke `rustc --print=calling-conventions` for a full list of supported calling conventions //~^^^ 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