Skip to content

Commit 86f8c4e

Browse files
committed
ADD - InvalidSymbolName to migrate symbol-name({}) error to new diagnostics infraestructure
ADD - dependencies needed to port a module to new Diagnostics infra (rustc_macros, rustc_errors, errors file, and fluent file)
1 parent 230a8ee commit 86f8c4e

File tree

7 files changed

+24
-1
lines changed

7 files changed

+24
-1
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4155,7 +4155,9 @@ dependencies = [
41554155
"punycode",
41564156
"rustc-demangle",
41574157
"rustc_data_structures",
4158+
"rustc_errors",
41584159
"rustc_hir",
4160+
"rustc_macros",
41594161
"rustc_middle",
41604162
"rustc_session",
41614163
"rustc_span",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
symbol_mangling_invalid_symbol_name = symbol-name({$mangled_formatted})

compiler/rustc_error_messages/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ fluent_messages! {
5252
ty_utils => "../locales/en-US/ty_utils.ftl",
5353
typeck => "../locales/en-US/typeck.ftl",
5454
mir_dataflow => "../locales/en-US/mir_dataflow.ftl",
55+
symbol_mangling => "../locales/en-US/symbol_mangling.ftl",
5556
}
5657

5758
pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};

compiler/rustc_symbol_mangling/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ rustc_hir = { path = "../rustc_hir" }
1818
rustc_target = { path = "../rustc_target" }
1919
rustc_data_structures = { path = "../rustc_data_structures" }
2020
rustc_session = { path = "../rustc_session" }
21+
rustc_macros = { path = "../rustc_macros" }
22+
rustc_errors = { path = "../rustc_errors" }
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//! Errors emitted by symbol_mangling.
2+
3+
use rustc_macros::SessionDiagnostic;
4+
use rustc_span::Span;
5+
6+
#[derive(SessionDiagnostic)]
7+
#[error(symbol_mangling::invalid_symbol_name)]
8+
pub struct InvalidSymbolName<'a> {
9+
#[primary_span]
10+
pub span: Span,
11+
pub mangled_formatted: &'a str,
12+
}

compiler/rustc_symbol_mangling/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ use tracing::debug;
110110
mod legacy;
111111
mod v0;
112112

113+
pub mod errors;
113114
pub mod test;
114115
pub mod typeid;
115116

compiler/rustc_symbol_mangling/src/test.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +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;
78
use rustc_hir::def_id::LocalDefId;
89
use rustc_middle::ty::print::with_no_trimmed_paths;
910
use rustc_middle::ty::{subst::InternalSubsts, Instance, TyCtxt};
@@ -59,7 +60,10 @@ impl SymbolNamesTest<'_> {
5960
tcx.erase_regions(InternalSubsts::identity_for_item(tcx, def_id)),
6061
);
6162
let mangled = tcx.symbol_name(instance);
62-
tcx.sess.span_err(attr.span, &format!("symbol-name({})", mangled));
63+
tcx.sess.emit_err(InvalidSymbolName {
64+
span: attr.span,
65+
mangled_formatted: &format!("{mangled}"),
66+
});
6367
if let Ok(demangling) = rustc_demangle::try_demangle(mangled.name) {
6468
tcx.sess.span_err(attr.span, &format!("demangling({})", demangling));
6569
tcx.sess.span_err(attr.span, &format!("demangling-alt({:#})", demangling));

0 commit comments

Comments
 (0)