about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2024-02-21 08:55:56 +0000
committerGitHub <noreply@github.com>2024-02-21 08:55:56 +0000
commit4840785cf8d6a1684403343e65ae664bbda23f18 (patch)
tree291abe42d467690088a552453f4eacf9624ae07a
parentd5206c6ecde0cb887518bc9142dcb6ac21cbbe94 (diff)
parentf68682fd484fc219192aa7ccf7bb1d809288df5e (diff)
downloadrust-4840785cf8d6a1684403343e65ae664bbda23f18.tar.gz
rust-4840785cf8d6a1684403343e65ae664bbda23f18.zip
Rollup merge of #121288 - tshepang:make-expand-translatable, r=michaelwoerister
make rustc_expand translatable

these are the last of the easy ones
-rw-r--r--compiler/rustc_expand/messages.ftl8
-rw-r--r--compiler/rustc_expand/src/errors.rs30
-rw-r--r--compiler/rustc_expand/src/proc_macro.rs24
3 files changed, 52 insertions, 10 deletions
diff --git a/compiler/rustc_expand/messages.ftl b/compiler/rustc_expand/messages.ftl
index 5a3303327db..1f0488130b2 100644
--- a/compiler/rustc_expand/messages.ftl
+++ b/compiler/rustc_expand/messages.ftl
@@ -22,6 +22,10 @@ expand_collapse_debuginfo_illegal =
 expand_count_repetition_misplaced =
     `count` can not be placed inside the inner-most repetition
 
+expand_custom_attribute_panicked =
+    custom attribute panicked
+    .help = message: {$message}
+
 expand_duplicate_matcher_binding = duplicate matcher binding
     .label = duplicate binding
     .label2 = previous binding
@@ -115,6 +119,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 929f3479466..fe901603c73 100644
--- a/compiler/rustc_expand/src/errors.rs
+++ b/compiler/rustc_expand/src/errors.rs
@@ -393,6 +393,36 @@ 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]
+    pub span: Span,
+    #[subdiagnostic]
+    pub message: Option<CustomAttributePanickedHelp>,
+}
+
+#[derive(Subdiagnostic)]
+#[help(expand_help)]
+pub(crate) struct CustomAttributePanickedHelp {
+    pub message: String,
+}
+
+#[derive(Diagnostic)]
 #[diag(expand_proc_macro_derive_tokens)]
 pub struct ProcMacroDeriveTokens {
     #[primary_span]
diff --git a/compiler/rustc_expand/src/proc_macro.rs b/compiler/rustc_expand/src/proc_macro.rs
index 2233cad2e63..23caf2f193a 100644
--- a/compiler/rustc_expand/src/proc_macro.rs
+++ b/compiler/rustc_expand/src/proc_macro.rs
@@ -93,11 +93,12 @@ impl base::AttrProcMacro for AttrProcMacro {
         let server = proc_macro_server::Rustc::new(ecx);
         self.client.run(&strategy, server, annotation, annotated, proc_macro_backtrace).map_err(
             |e| {
-                let mut err = ecx.dcx().struct_span_err(span, "custom attribute panicked");
-                if let Some(s) = e.as_str() {
-                    err.help(format!("message: {s}"));
-                }
-                err.emit()
+                ecx.dcx().emit_err(errors::CustomAttributePanicked {
+                    span,
+                    message: e.as_str().map(|message| errors::CustomAttributePanickedHelp {
+                        message: message.into(),
+                    }),
+                })
             },
         )
     }
@@ -146,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![]);
                 }
             }