ADD - migrate InvalidTraitItem and AltInvalidTraitItem errors
Thought of doing this by having a struct and an enum with Default and Alt cases, but not sure if we wanted to have the text in code instead of having “demangling()” and “demangling-alt()” in the ftl file. Don’t like the current way of having structs representing the same-ish and using long names to distinguish their expectations, instead of putting this in an enum and handling the different cases inside the type. I am fine with whichever option the team prefers; also understand having them as separate structs keeps it simple.
This commit is contained in:
parent
86f8c4e8e3
commit
359002bbeb
3 changed files with 29 additions and 3 deletions
|
@ -1 +1,5 @@
|
|||
symbol_mangling_invalid_symbol_name = symbol-name({$mangled_formatted})
|
||||
|
||||
symbol_mangling_invalid_trait_item = demangling({$demangling_formatted})
|
||||
|
||||
symbol_mangling_alt_invalid_trait_item = demangling-alt({$alt_demangling_formatted})
|
||||
|
|
|
@ -10,3 +10,19 @@ pub struct InvalidSymbolName<'a> {
|
|||
pub span: Span,
|
||||
pub mangled_formatted: &'a str,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error(symbol_mangling::invalid_trait_item)]
|
||||
pub struct InvalidTraitItem<'a> {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub demangling_formatted: &'a str,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error(symbol_mangling::alt_invalid_trait_item)]
|
||||
pub struct AltInvalidTraitItem<'a> {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub alt_demangling_formatted: &'a str,
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
//! def-path. This is used for unit testing the code that generates
|
||||
//! paths etc in all kinds of annoying scenarios.
|
||||
|
||||
use crate::errors::InvalidSymbolName;
|
||||
use crate::errors::{AltInvalidTraitItem, InvalidSymbolName, InvalidTraitItem};
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::{subst::InternalSubsts, Instance, TyCtxt};
|
||||
|
@ -65,8 +65,14 @@ impl SymbolNamesTest<'_> {
|
|||
mangled_formatted: &format!("{mangled}"),
|
||||
});
|
||||
if let Ok(demangling) = rustc_demangle::try_demangle(mangled.name) {
|
||||
tcx.sess.span_err(attr.span, &format!("demangling({})", demangling));
|
||||
tcx.sess.span_err(attr.span, &format!("demangling-alt({:#})", demangling));
|
||||
tcx.sess.emit_err(InvalidTraitItem {
|
||||
span: attr.span,
|
||||
demangling_formatted: &format!("{demangling}"),
|
||||
});
|
||||
tcx.sess.emit_err(AltInvalidTraitItem {
|
||||
span: attr.span,
|
||||
alt_demangling_formatted: &format!("{:#}", demangling),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue