Skip to content

Commit

Permalink
rustc_expand: make proc-macro derive error translatable
Browse files Browse the repository at this point in the history
  • Loading branch information
tshepang committed Mar 4, 2023
1 parent 70adb4e commit 7fe4f07
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions compiler/rustc_expand/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,6 @@ expand_trace_macro = trace_macro
expand_proc_macro_panicked =
proc macro panicked
.help = message: {$message}
expand_proc_macro_derive_tokens =
proc-macro derive produced unparseable tokens
7 changes: 7 additions & 0 deletions compiler/rustc_expand/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,10 @@ pub(crate) struct ProcMacroPanicked {
pub(crate) struct ProcMacroPanickedHelp {
pub message: String,
}

#[derive(Diagnostic)]
#[diag(expand_proc_macro_derive_tokens)]
pub struct ProcMacroDeriveTokens {
#[primary_span]
pub span: Span,
}
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/proc_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl MultiItemModifier for DeriveProcMacro {

// fail if there have been errors emitted
if ecx.sess.parse_sess.span_diagnostic.err_count() > error_count_before {
ecx.struct_span_err(span, "proc-macro derive produced unparseable tokens").emit();
ecx.sess.emit_err(errors::ProcMacroDeriveTokens { span });
}

ExpandResult::Ready(items)
Expand Down

0 comments on commit 7fe4f07

Please sign in to comment.