Skip to content

Commit 6150991

Browse files
committed
make "custom attribute panicked" translatable
1 parent 23a3d77 commit 6150991

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

compiler/rustc_expand/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ expand_collapse_debuginfo_illegal =
2222
expand_count_repetition_misplaced =
2323
`count` can not be placed inside the inner-most repetition
2424
25+
expand_custom_attribute_panicked =
26+
custom attribute panicked
27+
.help = message: {$message}
28+
2529
expand_duplicate_matcher_binding = duplicate matcher binding
2630
.label = duplicate binding
2731
.label2 = previous binding

compiler/rustc_expand/src/errors.rs

+15
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,21 @@ pub(crate) struct ProcMacroPanickedHelp {
392392
pub message: String,
393393
}
394394

395+
#[derive(Diagnostic)]
396+
#[diag(expand_custom_attribute_panicked)]
397+
pub(crate) struct CustomAttributePanicked {
398+
#[primary_span]
399+
pub span: Span,
400+
#[subdiagnostic]
401+
pub message: Option<CustomAttributePanickedHelp>,
402+
}
403+
404+
#[derive(Subdiagnostic)]
405+
#[help(expand_help)]
406+
pub(crate) struct CustomAttributePanickedHelp {
407+
pub message: String,
408+
}
409+
395410
#[derive(Diagnostic)]
396411
#[diag(expand_proc_macro_derive_tokens)]
397412
pub struct ProcMacroDeriveTokens {

compiler/rustc_expand/src/proc_macro.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@ impl base::AttrProcMacro for AttrProcMacro {
9393
let server = proc_macro_server::Rustc::new(ecx);
9494
self.client.run(&strategy, server, annotation, annotated, proc_macro_backtrace).map_err(
9595
|e| {
96-
let mut err = ecx.dcx().struct_span_err(span, "custom attribute panicked");
97-
if let Some(s) = e.as_str() {
98-
err.help(format!("message: {s}"));
99-
}
100-
err.emit()
96+
ecx.dcx().emit_err(errors::CustomAttributePanicked {
97+
span,
98+
message: e.as_str().map(|message| errors::CustomAttributePanickedHelp {
99+
message: message.into(),
100+
}),
101+
})
101102
},
102103
)
103104
}

0 commit comments

Comments
 (0)