Skip to content

Commit

Permalink
make "proc-macro derive panicked" translatable
Browse files Browse the repository at this point in the history
  • Loading branch information
tshepang committed Feb 19, 2024
1 parent 6150991 commit 5d43eec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_expand/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ expand_proc_macro_panicked =
proc macro panicked
.help = message: {$message}
expand_proc_macro_derive_panicked =
proc-macro derive panicked
.help = message: {$message}
expand_recursion_limit_reached =
recursion limit reached while expanding `{$descr}`
.help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`)
Expand Down
15 changes: 15 additions & 0 deletions compiler/rustc_expand/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 8 additions & 5 deletions compiler/rustc_expand/src/proc_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![]);
}
}
Expand Down

0 comments on commit 5d43eec

Please sign in to comment.