Skip to content

Commit 0965c7e

Browse files
authored
Rollup merge of rust-lang#108727 - tshepang:example-translatable-diagnostic, r=Nilstrieb
rustc_expand: make proc-macro derive error translatable kept this tiny so as to point to it as an example in rustc-dev-guide `@rustbot` label +A-translation
2 parents 6ce78a3 + 7fe4f07 commit 0965c7e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Diff for: compiler/rustc_expand/locales/en-US.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,6 @@ expand_trace_macro = trace_macro
133133
expand_proc_macro_panicked =
134134
proc macro panicked
135135
.help = message: {$message}
136+
137+
expand_proc_macro_derive_tokens =
138+
proc-macro derive produced unparseable tokens

Diff for: compiler/rustc_expand/src/errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,10 @@ pub(crate) struct ProcMacroPanicked {
390390
pub(crate) struct ProcMacroPanickedHelp {
391391
pub message: String,
392392
}
393+
394+
#[derive(Diagnostic)]
395+
#[diag(expand_proc_macro_derive_tokens)]
396+
pub struct ProcMacroDeriveTokens {
397+
#[primary_span]
398+
pub span: Span,
399+
}

Diff for: compiler/rustc_expand/src/proc_macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl MultiItemModifier for DeriveProcMacro {
176176

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

182182
ExpandResult::Ready(items)

0 commit comments

Comments
 (0)