about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTshepang Mbambo <tshepang@gmail.com>2023-03-04 07:54:29 +0200
committerTshepang Mbambo <tshepang@gmail.com>2023-03-04 07:54:29 +0200
commit7fe4f0701c34fd107101a6bdb2d62e0935d798a4 (patch)
tree04ede06da97e4e67d3c41d2e5237b724454aeea0
parent70adb4e5b4c8f8bde4ade0edcb0435ff7bf31281 (diff)
downloadrust-7fe4f0701c34fd107101a6bdb2d62e0935d798a4.tar.gz
rust-7fe4f0701c34fd107101a6bdb2d62e0935d798a4.zip
rustc_expand: make proc-macro derive error translatable
-rw-r--r--compiler/rustc_expand/locales/en-US.ftl3
-rw-r--r--compiler/rustc_expand/src/errors.rs7
-rw-r--r--compiler/rustc_expand/src/proc_macro.rs2
3 files changed, 11 insertions, 1 deletions
diff --git a/compiler/rustc_expand/locales/en-US.ftl b/compiler/rustc_expand/locales/en-US.ftl
index b475d285f6b..cfae781bdee 100644
--- a/compiler/rustc_expand/locales/en-US.ftl
+++ b/compiler/rustc_expand/locales/en-US.ftl
@@ -133,3 +133,6 @@ expand_trace_macro = trace_macro
 expand_proc_macro_panicked =
     proc macro panicked
     .help = message: {$message}
+
+expand_proc_macro_derive_tokens =
+    proc-macro derive produced unparseable tokens
diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs
index 70ab222b484..e5102a952e7 100644
--- a/compiler/rustc_expand/src/errors.rs
+++ b/compiler/rustc_expand/src/errors.rs
@@ -390,3 +390,10 @@ pub(crate) struct ProcMacroPanicked {
 pub(crate) struct ProcMacroPanickedHelp {
     pub message: String,
 }
+
+#[derive(Diagnostic)]
+#[diag(expand_proc_macro_derive_tokens)]
+pub struct ProcMacroDeriveTokens {
+    #[primary_span]
+    pub span: Span,
+}
diff --git a/compiler/rustc_expand/src/proc_macro.rs b/compiler/rustc_expand/src/proc_macro.rs
index cef64a10479..ddba1441719 100644
--- a/compiler/rustc_expand/src/proc_macro.rs
+++ b/compiler/rustc_expand/src/proc_macro.rs
@@ -176,7 +176,7 @@ impl MultiItemModifier for DeriveProcMacro {
 
         // fail if there have been errors emitted
         if ecx.sess.parse_sess.span_diagnostic.err_count() > error_count_before {
-            ecx.struct_span_err(span, "proc-macro derive produced unparseable tokens").emit();
+            ecx.sess.emit_err(errors::ProcMacroDeriveTokens { span });
         }
 
         ExpandResult::Ready(items)