Skip to content

Commit

Permalink
compiler: remove abi-specific extern "{abi}" suggestions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
workingjubilee committed Feb 7, 2025
1 parent 778dd25 commit f5512f4
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 69 deletions.
25 changes: 6 additions & 19 deletions compiler/rustc_abi/src/extern_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Abi, AbiUnsupported> {
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> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_abi/src/extern_abi/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 1 addition & 16 deletions compiler/rustc_ast_lowering/src/errors.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -32,8 +32,6 @@ pub(crate) struct InvalidAbi {
pub abi: Symbol,
pub command: String,
#[subdiagnostic]
pub explain: Option<InvalidAbiReason>,
#[subdiagnostic]
pub suggestion: Option<InvalidAbiSuggestion>,
}

Expand All @@ -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<G: EmissionGuarantee, F: SubdiagMessageOp<G>>(
self,
diag: &mut Diag<'_, G>,
_: &F,
) {
#[allow(rustc::untranslatable_diagnostic)]
diag.note(self.0);
}
}

#[derive(Subdiagnostic)]
#[suggestion(
ast_lowering_invalid_abi_suggestion,
Expand Down
13 changes: 4 additions & 9 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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;
Expand All @@ -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))
Expand All @@ -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}\""),
Expand Down
4 changes: 0 additions & 4 deletions tests/ui/abi/removed-wasm-abi.rs

This file was deleted.

12 changes: 0 additions & 12 deletions tests/ui/abi/removed-wasm-abi.stderr

This file was deleted.

4 changes: 1 addition & 3 deletions tests/ui/abi/riscv-discoverability-guidance.riscv32.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ LL | extern "riscv-interrupt" fn isr() {}
| 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
--> $DIR/riscv-discoverability-guidance.rs:22:8
|
LL | extern "riscv-interrupt-u" fn isr_U() {}
| ^^^^^^^^^^^^^^^^^^^
Expand All @@ -20,7 +19,6 @@ LL | extern "riscv-interrupt-u" fn isr_U() {}
| 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

Expand Down
4 changes: 1 addition & 3 deletions tests/ui/abi/riscv-discoverability-guidance.riscv64.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ LL | extern "riscv-interrupt" fn isr() {}
| 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
--> $DIR/riscv-discoverability-guidance.rs:22:8
|
LL | extern "riscv-interrupt-u" fn isr_U() {}
| ^^^^^^^^^^^^^^^^^^^
Expand All @@ -20,7 +19,6 @@ LL | extern "riscv-interrupt-u" fn isr_U() {}
| 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

Expand Down
2 changes: 0 additions & 2 deletions tests/ui/abi/riscv-discoverability-guidance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ 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

0 comments on commit f5512f4

Please sign in to comment.