Skip to content

Commit 359002b

Browse files
committed
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.
1 parent 86f8c4e commit 359002b

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
symbol_mangling_invalid_symbol_name = symbol-name({$mangled_formatted})
2+
3+
symbol_mangling_invalid_trait_item = demangling({$demangling_formatted})
4+
5+
symbol_mangling_alt_invalid_trait_item = demangling-alt({$alt_demangling_formatted})

compiler/rustc_symbol_mangling/src/errors.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,19 @@ pub struct InvalidSymbolName<'a> {
1010
pub span: Span,
1111
pub mangled_formatted: &'a str,
1212
}
13+
14+
#[derive(SessionDiagnostic)]
15+
#[error(symbol_mangling::invalid_trait_item)]
16+
pub struct InvalidTraitItem<'a> {
17+
#[primary_span]
18+
pub span: Span,
19+
pub demangling_formatted: &'a str,
20+
}
21+
22+
#[derive(SessionDiagnostic)]
23+
#[error(symbol_mangling::alt_invalid_trait_item)]
24+
pub struct AltInvalidTraitItem<'a> {
25+
#[primary_span]
26+
pub span: Span,
27+
pub alt_demangling_formatted: &'a str,
28+
}

compiler/rustc_symbol_mangling/src/test.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! def-path. This is used for unit testing the code that generates
55
//! paths etc in all kinds of annoying scenarios.
66
7-
use crate::errors::InvalidSymbolName;
7+
use crate::errors::{AltInvalidTraitItem, InvalidSymbolName, InvalidTraitItem};
88
use rustc_hir::def_id::LocalDefId;
99
use rustc_middle::ty::print::with_no_trimmed_paths;
1010
use rustc_middle::ty::{subst::InternalSubsts, Instance, TyCtxt};
@@ -65,8 +65,14 @@ impl SymbolNamesTest<'_> {
6565
mangled_formatted: &format!("{mangled}"),
6666
});
6767
if let Ok(demangling) = rustc_demangle::try_demangle(mangled.name) {
68-
tcx.sess.span_err(attr.span, &format!("demangling({})", demangling));
69-
tcx.sess.span_err(attr.span, &format!("demangling-alt({:#})", demangling));
68+
tcx.sess.emit_err(InvalidTraitItem {
69+
span: attr.span,
70+
demangling_formatted: &format!("{demangling}"),
71+
});
72+
tcx.sess.emit_err(AltInvalidTraitItem {
73+
span: attr.span,
74+
alt_demangling_formatted: &format!("{:#}", demangling),
75+
});
7076
}
7177
}
7278

0 commit comments

Comments
 (0)