about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJhonny Bill Mena <jhonnybillm@gmail.com>2022-08-27 00:24:13 -0400
committerJhonny Bill Mena <jhonnybillm@gmail.com>2022-08-30 14:27:42 -0400
commit86f8c4e8e3136ee1831ffaa9d6fbdac7267d35ea (patch)
tree49cc40e40cc899a88af96556d5d84382fce1f8e9
parent230a8ee364b693c286a2187e56239cd2cc3be318 (diff)
downloadrust-86f8c4e8e3136ee1831ffaa9d6fbdac7267d35ea.tar.gz
rust-86f8c4e8e3136ee1831ffaa9d6fbdac7267d35ea.zip
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)
-rw-r--r--Cargo.lock2
-rw-r--r--compiler/rustc_error_messages/locales/en-US/symbol_mangling.ftl1
-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.rs12
-rw-r--r--compiler/rustc_symbol_mangling/src/lib.rs1
-rw-r--r--compiler/rustc_symbol_mangling/src/test.rs6
7 files changed, 24 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 21d522cb9ff..6cddbe9d2cd 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4155,7 +4155,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..6c8166beab8
--- /dev/null
+++ b/compiler/rustc_error_messages/locales/en-US/symbol_mangling.ftl
@@ -0,0 +1 @@
+symbol_mangling_invalid_symbol_name = symbol-name({$mangled_formatted})
diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs
index d1ac326a72c..eabb9192029 100644
--- a/compiler/rustc_error_messages/src/lib.rs
+++ b/compiler/rustc_error_messages/src/lib.rs
@@ -52,6 +52,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..38aa4345f0c
--- /dev/null
+++ b/compiler/rustc_symbol_mangling/src/errors.rs
@@ -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,
+}
diff --git a/compiler/rustc_symbol_mangling/src/lib.rs b/compiler/rustc_symbol_mangling/src/lib.rs
index 5fc992023ca..252726691a7 100644
--- a/compiler/rustc_symbol_mangling/src/lib.rs
+++ b/compiler/rustc_symbol_mangling/src/lib.rs
@@ -110,6 +110,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..9c1d5d4292c 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::InvalidSymbolName;
 use rustc_hir::def_id::LocalDefId;
 use rustc_middle::ty::print::with_no_trimmed_paths;
 use rustc_middle::ty::{subst::InternalSubsts, Instance, TyCtxt};
@@ -59,7 +60,10 @@ 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));