about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2022-08-31 14:29:53 +0200
committerGitHub <noreply@github.com>2022-08-31 14:29:53 +0200
commit59d2c1917a61d32109f1d2fb33d5956be813976d (patch)
tree0381df8a5e3aa660c01e9469ad7f550bcac9f3ee
parent24922b7a828361399aeed73a802e786f035a6d4f (diff)
parent3ee69463164ac33af6eb483ccd2f64b06730c220 (diff)
downloadrust-59d2c1917a61d32109f1d2fb33d5956be813976d.tar.gz
rust-59d2c1917a61d32109f1d2fb33d5956be813976d.zip
Rollup merge of #100831 - JhonnyBillM:migrate-symbol-mangling-to-diagnostics-structs, r=davidtwco
Migrate `symbol_mangling` module to new diagnostics structs
-rw-r--r--Cargo.lock2
-rw-r--r--compiler/rustc_error_messages/locales/en-US/symbol_mangling.ftl7
-rw-r--r--compiler/rustc_error_messages/src/lib.rs1
-rw-r--r--compiler/rustc_symbol_mangling/Cargo.toml2
-rw-r--r--compiler/rustc_symbol_mangling/src/errors.rs36
-rw-r--r--compiler/rustc_symbol_mangling/src/lib.rs3
-rw-r--r--compiler/rustc_symbol_mangling/src/test.rs22
7 files changed, 68 insertions, 5 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4aa7ee206dc..002d73be7d1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4156,7 +4156,9 @@ dependencies = [
  "punycode",
  "rustc-demangle",
  "rustc_data_structures",
+ "rustc_errors",
  "rustc_hir",
+ "rustc_macros",
  "rustc_middle",
  "rustc_session",
  "rustc_span",
diff --git a/compiler/rustc_error_messages/locales/en-US/symbol_mangling.ftl b/compiler/rustc_error_messages/locales/en-US/symbol_mangling.ftl
new file mode 100644
index 00000000000..55d6fbbf86f
--- /dev/null
+++ b/compiler/rustc_error_messages/locales/en-US/symbol_mangling.ftl
@@ -0,0 +1,7 @@
+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_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs
index 254e96ddd63..42fb2d538b0 100644
--- a/compiler/rustc_error_messages/src/lib.rs
+++ b/compiler/rustc_error_messages/src/lib.rs
@@ -54,6 +54,7 @@ fluent_messages! {
     ty_utils => "../locales/en-US/ty_utils.ftl",
     typeck => "../locales/en-US/typeck.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};
diff --git a/compiler/rustc_symbol_mangling/Cargo.toml b/compiler/rustc_symbol_mangling/Cargo.toml
index b104a40c231..3db05225722 100644
--- a/compiler/rustc_symbol_mangling/Cargo.toml
+++ b/compiler/rustc_symbol_mangling/Cargo.toml
@@ -18,3 +18,5 @@ rustc_hir = { path = "../rustc_hir" }
 rustc_target = { path = "../rustc_target" }
 rustc_data_structures = { path = "../rustc_data_structures" }
 rustc_session = { path = "../rustc_session" }
+rustc_macros = { path = "../rustc_macros" }
+rustc_errors = { path = "../rustc_errors" }
diff --git a/compiler/rustc_symbol_mangling/src/errors.rs b/compiler/rustc_symbol_mangling/src/errors.rs
new file mode 100644
index 00000000000..242997365a8
--- /dev/null
+++ b/compiler/rustc_symbol_mangling/src/errors.rs
@@ -0,0 +1,36 @@
+//! Errors emitted by symbol_mangling.
+
+use rustc_macros::SessionDiagnostic;
+use rustc_span::Span;
+
+#[derive(SessionDiagnostic)]
+#[diag(symbol_mangling::invalid_symbol_name)]
+pub struct InvalidSymbolName {
+    #[primary_span]
+    pub span: Span,
+    pub mangled_formatted: String,
+}
+
+#[derive(SessionDiagnostic)]
+#[diag(symbol_mangling::invalid_trait_item)]
+pub struct InvalidTraitItem {
+    #[primary_span]
+    pub span: Span,
+    pub demangling_formatted: String,
+}
+
+#[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,
+}
diff --git a/compiler/rustc_symbol_mangling/src/lib.rs b/compiler/rustc_symbol_mangling/src/lib.rs
index 5fc992023ca..0c6489acb34 100644
--- a/compiler/rustc_symbol_mangling/src/lib.rs
+++ b/compiler/rustc_symbol_mangling/src/lib.rs
@@ -91,6 +91,8 @@
 #![feature(never_type)]
 #![recursion_limit = "256"]
 #![allow(rustc::potential_query_instability)]
+#![deny(rustc::untranslatable_diagnostic)]
+#![deny(rustc::diagnostic_outside_of_impl)]
 
 #[macro_use]
 extern crate rustc_middle;
@@ -110,6 +112,7 @@ use tracing::debug;
 mod legacy;
 mod v0;
 
+pub mod errors;
 pub mod test;
 pub mod typeid;
 
diff --git a/compiler/rustc_symbol_mangling/src/test.rs b/compiler/rustc_symbol_mangling/src/test.rs
index 7249ce04c15..b1c4cab11eb 100644
--- a/compiler/rustc_symbol_mangling/src/test.rs
+++ b/compiler/rustc_symbol_mangling/src/test.rs
@@ -4,6 +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 rustc_hir::def_id::LocalDefId;
 use rustc_middle::ty::print::with_no_trimmed_paths;
 use rustc_middle::ty::{subst::InternalSubsts, Instance, TyCtxt};
@@ -59,16 +60,27 @@ impl SymbolNamesTest<'_> {
                 tcx.erase_regions(InternalSubsts::identity_for_item(tcx, def_id)),
             );
             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) {
-                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),
+                });
             }
         }
 
         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())),
+            });
         }
     }
 }