about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJhonny Bill Mena <jhonnybillm@gmail.com>2022-08-21 00:38:23 -0400
committerJhonny Bill Mena <jhonnybillm@gmail.com>2022-08-30 14:27:42 -0400
commit359002bbebb5a3879af4d957001b6526ae4c550e (patch)
treef4ae399d40f467d78e3e53f784de6c0fdee28e07
parent86f8c4e8e3136ee1831ffaa9d6fbdac7267d35ea (diff)
downloadrust-359002bbebb5a3879af4d957001b6526ae4c550e.tar.gz
rust-359002bbebb5a3879af4d957001b6526ae4c550e.zip
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.
-rw-r--r--compiler/rustc_error_messages/locales/en-US/symbol_mangling.ftl4
-rw-r--r--compiler/rustc_symbol_mangling/src/errors.rs16
-rw-r--r--compiler/rustc_symbol_mangling/src/test.rs12
3 files changed, 29 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 6c8166beab8..644c8f84c28 100644
--- a/compiler/rustc_error_messages/locales/en-US/symbol_mangling.ftl
+++ b/compiler/rustc_error_messages/locales/en-US/symbol_mangling.ftl
@@ -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})
diff --git a/compiler/rustc_symbol_mangling/src/errors.rs b/compiler/rustc_symbol_mangling/src/errors.rs
index 38aa4345f0c..db8b3159a6f 100644
--- a/compiler/rustc_symbol_mangling/src/errors.rs
+++ b/compiler/rustc_symbol_mangling/src/errors.rs
@@ -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,
+}
diff --git a/compiler/rustc_symbol_mangling/src/test.rs b/compiler/rustc_symbol_mangling/src/test.rs
index 9c1d5d4292c..06efefb726c 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::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),
+                });
             }
         }