about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTshepang Mbambo <tshepang@gmail.com>2024-02-19 06:02:14 +0200
committerTshepang Mbambo <tshepang@gmail.com>2024-02-19 09:23:26 +0200
commit61509914a3debdf6ff809c35af15cc5cabcc32a0 (patch)
treed699c7bb7e605840ba73592c3b83f85376b88e9a
parent23a3d777c8a95715977608c827de63e7738fa228 (diff)
downloadrust-61509914a3debdf6ff809c35af15cc5cabcc32a0.tar.gz
rust-61509914a3debdf6ff809c35af15cc5cabcc32a0.zip
make "custom attribute 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.rs11
3 files changed, 25 insertions, 5 deletions
diff --git a/compiler/rustc_expand/messages.ftl b/compiler/rustc_expand/messages.ftl
index 3e3b4814300..cae4df6cd4b 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
diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs
index 2584ff62e98..5bbf4411bc3 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_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..170857e62ff 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(),
+                    }),
+                })
             },
         )
     }