about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTshepang Mbambo <tshepang@gmail.com>2024-02-20 08:31:13 +0200
committerTshepang Mbambo <tshepang@gmail.com>2024-02-20 08:31:13 +0200
commitf68682fd484fc219192aa7ccf7bb1d809288df5e (patch)
tree0a245df5a2586678a547de3e2ee23dd1a0eb480e
parent61509914a3debdf6ff809c35af15cc5cabcc32a0 (diff)
downloadrust-f68682fd484fc219192aa7ccf7bb1d809288df5e.tar.gz
rust-f68682fd484fc219192aa7ccf7bb1d809288df5e.zip
make "proc-macro derive panicked" translatable
-rw-r--r--compiler/rustc_expand/messages.ftl4
-rw-r--r--compiler/rustc_expand/src/errors.rs15
-rw-r--r--compiler/rustc_expand/src/proc_macro.rs13
3 files changed, 27 insertions, 5 deletions
diff --git a/compiler/rustc_expand/messages.ftl b/compiler/rustc_expand/messages.ftl
index cae4df6cd4b..c82a0242c5b 100644
--- a/compiler/rustc_expand/messages.ftl
+++ b/compiler/rustc_expand/messages.ftl
@@ -114,6 +114,10 @@ expand_only_one_argument =
 expand_only_one_word =
     must only be one word
 
+expand_proc_macro_derive_panicked =
+    proc-macro derive panicked
+    .help = message: {$message}
+
 expand_proc_macro_derive_tokens =
     proc-macro derive produced unparsable tokens
 
diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs
index 5bbf4411bc3..299ba8a1fdf 100644
--- a/compiler/rustc_expand/src/errors.rs
+++ b/compiler/rustc_expand/src/errors.rs
@@ -393,6 +393,21 @@ pub(crate) struct ProcMacroPanickedHelp {
 }
 
 #[derive(Diagnostic)]
+#[diag(expand_proc_macro_derive_panicked)]
+pub(crate) struct ProcMacroDerivePanicked {
+    #[primary_span]
+    pub span: Span,
+    #[subdiagnostic]
+    pub message: Option<ProcMacroDerivePanickedHelp>,
+}
+
+#[derive(Subdiagnostic)]
+#[help(expand_help)]
+pub(crate) struct ProcMacroDerivePanickedHelp {
+    pub message: String,
+}
+
+#[derive(Diagnostic)]
 #[diag(expand_custom_attribute_panicked)]
 pub(crate) struct CustomAttributePanicked {
     #[primary_span]
diff --git a/compiler/rustc_expand/src/proc_macro.rs b/compiler/rustc_expand/src/proc_macro.rs
index 170857e62ff..23caf2f193a 100644
--- a/compiler/rustc_expand/src/proc_macro.rs
+++ b/compiler/rustc_expand/src/proc_macro.rs
@@ -147,11 +147,14 @@ impl MultiItemModifier for DeriveProcMacro {
             match self.client.run(&strategy, server, input, proc_macro_backtrace) {
                 Ok(stream) => stream,
                 Err(e) => {
-                    let mut err = ecx.dcx().struct_span_err(span, "proc-macro derive panicked");
-                    if let Some(s) = e.as_str() {
-                        err.help(format!("message: {s}"));
-                    }
-                    err.emit();
+                    ecx.dcx().emit_err({
+                        errors::ProcMacroDerivePanicked {
+                            span,
+                            message: e.as_str().map(|message| {
+                                errors::ProcMacroDerivePanickedHelp { message: message.into() }
+                            }),
+                        }
+                    });
                     return ExpandResult::Ready(vec![]);
                 }
             }