Skip to content

Commit f68682f

Browse files
committed
make "proc-macro derive panicked" translatable
1 parent 6150991 commit f68682f

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

compiler/rustc_expand/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ expand_only_one_argument =
114114
expand_only_one_word =
115115
must only be one word
116116
117+
expand_proc_macro_derive_panicked =
118+
proc-macro derive panicked
119+
.help = message: {$message}
120+
117121
expand_proc_macro_derive_tokens =
118122
proc-macro derive produced unparsable tokens
119123

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_proc_macro_derive_panicked)]
397+
pub(crate) struct ProcMacroDerivePanicked {
398+
#[primary_span]
399+
pub span: Span,
400+
#[subdiagnostic]
401+
pub message: Option<ProcMacroDerivePanickedHelp>,
402+
}
403+
404+
#[derive(Subdiagnostic)]
405+
#[help(expand_help)]
406+
pub(crate) struct ProcMacroDerivePanickedHelp {
407+
pub message: String,
408+
}
409+
395410
#[derive(Diagnostic)]
396411
#[diag(expand_custom_attribute_panicked)]
397412
pub(crate) struct CustomAttributePanicked {

compiler/rustc_expand/src/proc_macro.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,14 @@ impl MultiItemModifier for DeriveProcMacro {
147147
match self.client.run(&strategy, server, input, proc_macro_backtrace) {
148148
Ok(stream) => stream,
149149
Err(e) => {
150-
let mut err = ecx.dcx().struct_span_err(span, "proc-macro derive panicked");
151-
if let Some(s) = e.as_str() {
152-
err.help(format!("message: {s}"));
153-
}
154-
err.emit();
150+
ecx.dcx().emit_err({
151+
errors::ProcMacroDerivePanicked {
152+
span,
153+
message: e.as_str().map(|message| {
154+
errors::ProcMacroDerivePanickedHelp { message: message.into() }
155+
}),
156+
}
157+
});
155158
return ExpandResult::Ready(vec![]);
156159
}
157160
}

0 commit comments

Comments
 (0)