From 8f5fada86df26aaccbf4f5e5851ac040b5ea5852 Mon Sep 17 00:00:00 2001 From: Jhonny Bill Mena Date: Sun, 21 Aug 2022 00:51:33 -0400 Subject: [PATCH] ADD - migrate InvalidDefPath to new diagnostics infra --- .../locales/en-US/symbol_mangling.ftl | 2 ++ compiler/rustc_symbol_mangling/src/errors.rs | 8 ++++++++ compiler/rustc_symbol_mangling/src/test.rs | 8 +++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_error_messages/locales/en-US/symbol_mangling.ftl b/compiler/rustc_error_messages/locales/en-US/symbol_mangling.ftl index 644c8f84c28..55d6fbbf86f 100644 --- a/compiler/rustc_error_messages/locales/en-US/symbol_mangling.ftl +++ b/compiler/rustc_error_messages/locales/en-US/symbol_mangling.ftl @@ -3,3 +3,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}) + +symbol_mangling_invalid_def_path = def-path({$def_path}) diff --git a/compiler/rustc_symbol_mangling/src/errors.rs b/compiler/rustc_symbol_mangling/src/errors.rs index c0e49e07bfc..4872dfa2653 100644 --- a/compiler/rustc_symbol_mangling/src/errors.rs +++ b/compiler/rustc_symbol_mangling/src/errors.rs @@ -26,3 +26,11 @@ pub struct AltInvalidTraitItem { pub span: Span, pub alt_demangling_formatted: String, } + +#[derive(SessionDiagnostic)] +#[error(symbol_mangling::invalid_def_path)] +pub struct InvalidDefPath { + #[primary_span] + pub span: Span, + pub def_path: String, +} diff --git a/compiler/rustc_symbol_mangling/src/test.rs b/compiler/rustc_symbol_mangling/src/test.rs index 2ed1dea357d..b1c4cab11eb 100644 --- a/compiler/rustc_symbol_mangling/src/test.rs +++ b/compiler/rustc_symbol_mangling/src/test.rs @@ -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::{AltInvalidTraitItem, InvalidSymbolName, InvalidTraitItem}; +use crate::errors::{AltInvalidTraitItem, InvalidDefPath, 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}; @@ -77,8 +77,10 @@ impl SymbolNamesTest<'_> { } for attr in tcx.get_attrs(def_id.to_def_id(), DEF_PATH) { - let path = with_no_trimmed_paths!(tcx.def_path_str(def_id.to_def_id())); - tcx.sess.span_err(attr.span, &format!("def-path({})", path)); + tcx.sess.emit_err(InvalidDefPath { + span: attr.span, + def_path: with_no_trimmed_paths!(tcx.def_path_str(def_id.to_def_id())), + }); } } }