make "proc-macro derive panicked" translatable

This commit is contained in:
Tshepang Mbambo 2024-02-20 08:31:13 +02:00
parent 61509914a3
commit f68682fd48
3 changed files with 27 additions and 5 deletions

View file

@ -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

View file

@ -392,6 +392,21 @@ pub(crate) struct ProcMacroPanickedHelp {
pub message: String,
}
#[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 {

View file

@ -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![]);
}
}