about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorJhonny Bill Mena <jhonnybillm@gmail.com>2022-09-13 16:19:32 -0400
committerJhonny Bill Mena <jhonnybillm@gmail.com>2022-09-13 16:19:32 -0400
commitc846ba6e53f3a1b8627034764d85d6f9e929c243 (patch)
tree823903fe1278f042429f1d2d2fd167014b517d12 /compiler
parent1ce51982b8550c782ded466c1abff0d2b2e21c4e (diff)
downloadrust-c846ba6e53f3a1b8627034764d85d6f9e929c243.tar.gz
rust-c846ba6e53f3a1b8627034764d85d6f9e929c243.zip
UPDATE - merge and avoid translations for symbol mangling test output
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_error_messages/locales/en-US/symbol_mangling.ftl8
-rw-r--r--compiler/rustc_symbol_mangling/src/errors.rs44
-rw-r--r--compiler/rustc_symbol_mangling/src/test.rs22
3 files changed, 35 insertions, 39 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 55d6fbbf86f..b7d48280f46 100644
--- a/compiler/rustc_error_messages/locales/en-US/symbol_mangling.ftl
+++ b/compiler/rustc_error_messages/locales/en-US/symbol_mangling.ftl
@@ -1,7 +1 @@
-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})
+symbol_mangling_test_output = {$kind}({$content})
diff --git a/compiler/rustc_symbol_mangling/src/errors.rs b/compiler/rustc_symbol_mangling/src/errors.rs
index 242997365a8..664d2543f1f 100644
--- a/compiler/rustc_symbol_mangling/src/errors.rs
+++ b/compiler/rustc_symbol_mangling/src/errors.rs
@@ -1,36 +1,34 @@
 //! Errors emitted by symbol_mangling.
 
+use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
 use rustc_macros::SessionDiagnostic;
 use rustc_span::Span;
 
 #[derive(SessionDiagnostic)]
-#[diag(symbol_mangling::invalid_symbol_name)]
-pub struct InvalidSymbolName {
+#[diag(symbol_mangling::test_output)]
+pub struct TestOutput {
     #[primary_span]
     pub span: Span,
-    pub mangled_formatted: String,
+    pub kind: Kind,
+    pub content: String,
 }
 
-#[derive(SessionDiagnostic)]
-#[diag(symbol_mangling::invalid_trait_item)]
-pub struct InvalidTraitItem {
-    #[primary_span]
-    pub span: Span,
-    pub demangling_formatted: String,
+pub enum Kind {
+    SymbolName,
+    Demangling,
+    DemanglingAlt,
+    DefPath,
 }
 
-#[derive(SessionDiagnostic)]
-#[diag(symbol_mangling::alt_invalid_trait_item)]
-pub struct AltInvalidTraitItem {
-    #[primary_span]
-    pub span: Span,
-    pub alt_demangling_formatted: String,
-}
-
-#[derive(SessionDiagnostic)]
-#[diag(symbol_mangling::invalid_def_path)]
-pub struct InvalidDefPath {
-    #[primary_span]
-    pub span: Span,
-    pub def_path: String,
+impl IntoDiagnosticArg for Kind {
+    fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
+        let kind = match self {
+            Kind::SymbolName => "symbol-name",
+            Kind::Demangling => "demangling",
+            Kind::DemanglingAlt => "demangling-alt",
+            Kind::DefPath => "def-path",
+        }
+        .into();
+        DiagnosticArgValue::Str(kind)
+    }
 }
diff --git a/compiler/rustc_symbol_mangling/src/test.rs b/compiler/rustc_symbol_mangling/src/test.rs
index b1c4cab11eb..9d89c9c52b2 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, InvalidDefPath, InvalidSymbolName, InvalidTraitItem};
+use crate::errors::{Kind, TestOutput};
 use rustc_hir::def_id::LocalDefId;
 use rustc_middle::ty::print::with_no_trimmed_paths;
 use rustc_middle::ty::{subst::InternalSubsts, Instance, TyCtxt};
@@ -60,26 +60,30 @@ impl SymbolNamesTest<'_> {
                 tcx.erase_regions(InternalSubsts::identity_for_item(tcx, def_id)),
             );
             let mangled = tcx.symbol_name(instance);
-            tcx.sess.emit_err(InvalidSymbolName {
+            tcx.sess.emit_err(TestOutput {
                 span: attr.span,
-                mangled_formatted: format!("{mangled}"),
+                kind: Kind::SymbolName,
+                content: format!("{mangled}"),
             });
             if let Ok(demangling) = rustc_demangle::try_demangle(mangled.name) {
-                tcx.sess.emit_err(InvalidTraitItem {
+                tcx.sess.emit_err(TestOutput {
                     span: attr.span,
-                    demangling_formatted: format!("{demangling}"),
+                    kind: Kind::Demangling,
+                    content: format!("{demangling}"),
                 });
-                tcx.sess.emit_err(AltInvalidTraitItem {
+                tcx.sess.emit_err(TestOutput {
                     span: attr.span,
-                    alt_demangling_formatted: format!("{:#}", demangling),
+                    kind: Kind::DemanglingAlt,
+                    content: format!("{:#}", demangling),
                 });
             }
         }
 
         for attr in tcx.get_attrs(def_id.to_def_id(), DEF_PATH) {
-            tcx.sess.emit_err(InvalidDefPath {
+            tcx.sess.emit_err(TestOutput {
                 span: attr.span,
-                def_path: with_no_trimmed_paths!(tcx.def_path_str(def_id.to_def_id())),
+                kind: Kind::DefPath,
+                content: with_no_trimmed_paths!(tcx.def_path_str(def_id.to_def_id())),
             });
         }
     }