rustc_expand: make proc-macro derive error translatable

This commit is contained in:
Tshepang Mbambo 2023-03-04 07:54:29 +02:00
parent 70adb4e5b4
commit 7fe4f0701c
3 changed files with 11 additions and 1 deletions

View file

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

View file

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

View file

@ -176,7 +176,7 @@ fn expand(
// 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)