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)
This commit is contained in:
Jhonny Bill Mena 2022-08-27 00:24:13 -04:00
parent 230a8ee364
commit 86f8c4e8e3
7 changed files with 24 additions and 1 deletions

View File

@ -4155,7 +4155,9 @@ dependencies = [
"punycode", "punycode",
"rustc-demangle", "rustc-demangle",
"rustc_data_structures", "rustc_data_structures",
"rustc_errors",
"rustc_hir", "rustc_hir",
"rustc_macros",
"rustc_middle", "rustc_middle",
"rustc_session", "rustc_session",
"rustc_span", "rustc_span",

View File

@ -0,0 +1 @@
symbol_mangling_invalid_symbol_name = symbol-name({$mangled_formatted})

View File

@ -52,6 +52,7 @@
ty_utils => "../locales/en-US/ty_utils.ftl", ty_utils => "../locales/en-US/ty_utils.ftl",
typeck => "../locales/en-US/typeck.ftl", typeck => "../locales/en-US/typeck.ftl",
mir_dataflow => "../locales/en-US/mir_dataflow.ftl", mir_dataflow => "../locales/en-US/mir_dataflow.ftl",
symbol_mangling => "../locales/en-US/symbol_mangling.ftl",
} }
pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES}; pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};

View File

@ -18,3 +18,5 @@ rustc_hir = { path = "../rustc_hir" }
rustc_target = { path = "../rustc_target" } rustc_target = { path = "../rustc_target" }
rustc_data_structures = { path = "../rustc_data_structures" } rustc_data_structures = { path = "../rustc_data_structures" }
rustc_session = { path = "../rustc_session" } rustc_session = { path = "../rustc_session" }
rustc_macros = { path = "../rustc_macros" }
rustc_errors = { path = "../rustc_errors" }

View File

@ -0,0 +1,12 @@
//! Errors emitted by symbol_mangling.
use rustc_macros::SessionDiagnostic;
use rustc_span::Span;
#[derive(SessionDiagnostic)]
#[error(symbol_mangling::invalid_symbol_name)]
pub struct InvalidSymbolName<'a> {
#[primary_span]
pub span: Span,
pub mangled_formatted: &'a str,
}

View File

@ -110,6 +110,7 @@
mod legacy; mod legacy;
mod v0; mod v0;
pub mod errors;
pub mod test; pub mod test;
pub mod typeid; pub mod typeid;

View File

@ -4,6 +4,7 @@
//! def-path. This is used for unit testing the code that generates //! def-path. This is used for unit testing the code that generates
//! paths etc in all kinds of annoying scenarios. //! paths etc in all kinds of annoying scenarios.
use crate::errors::InvalidSymbolName;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{subst::InternalSubsts, Instance, TyCtxt}; use rustc_middle::ty::{subst::InternalSubsts, Instance, TyCtxt};
@ -59,7 +60,10 @@ fn process_attrs(&mut self, def_id: LocalDefId) {
tcx.erase_regions(InternalSubsts::identity_for_item(tcx, def_id)), tcx.erase_regions(InternalSubsts::identity_for_item(tcx, def_id)),
); );
let mangled = tcx.symbol_name(instance); let mangled = tcx.symbol_name(instance);
tcx.sess.span_err(attr.span, &format!("symbol-name({})", mangled)); tcx.sess.emit_err(InvalidSymbolName {
span: attr.span,
mangled_formatted: &format!("{mangled}"),
});
if let Ok(demangling) = rustc_demangle::try_demangle(mangled.name) { 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({})", demangling));
tcx.sess.span_err(attr.span, &format!("demangling-alt({:#})", demangling)); tcx.sess.span_err(attr.span, &format!("demangling-alt({:#})", demangling));