Skip to content

Commit 4840785

Browse files
authored
Rollup merge of rust-lang#121288 - tshepang:make-expand-translatable, r=michaelwoerister
make rustc_expand translatable these are the last of the easy ones
2 parents d5206c6 + f68682f commit 4840785

File tree

3 files changed

+52
-10
lines changed

3 files changed

+52
-10
lines changed

compiler/rustc_expand/messages.ftl

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ expand_collapse_debuginfo_illegal =
2222
expand_count_repetition_misplaced =
2323
`count` can not be placed inside the inner-most repetition
2424
25+
expand_custom_attribute_panicked =
26+
custom attribute panicked
27+
.help = message: {$message}
28+
2529
expand_duplicate_matcher_binding = duplicate matcher binding
2630
.label = duplicate binding
2731
.label2 = previous binding
@@ -115,6 +119,10 @@ expand_only_one_argument =
115119
expand_only_one_word =
116120
must only be one word
117121
122+
expand_proc_macro_derive_panicked =
123+
proc-macro derive panicked
124+
.help = message: {$message}
125+
118126
expand_proc_macro_derive_tokens =
119127
proc-macro derive produced unparsable tokens
120128

compiler/rustc_expand/src/errors.rs

+30
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,36 @@ pub(crate) struct ProcMacroPanickedHelp {
392392
pub message: String,
393393
}
394394

395+
#[derive(Diagnostic)]
396+
#[diag(expand_proc_macro_derive_panicked)]
397+
pub(crate) struct ProcMacroDerivePanicked {
398+
#[primary_span]
399+
pub span: Span,
400+
#[subdiagnostic]
401+
pub message: Option<ProcMacroDerivePanickedHelp>,
402+
}
403+
404+
#[derive(Subdiagnostic)]
405+
#[help(expand_help)]
406+
pub(crate) struct ProcMacroDerivePanickedHelp {
407+
pub message: String,
408+
}
409+
410+
#[derive(Diagnostic)]
411+
#[diag(expand_custom_attribute_panicked)]
412+
pub(crate) struct CustomAttributePanicked {
413+
#[primary_span]
414+
pub span: Span,
415+
#[subdiagnostic]
416+
pub message: Option<CustomAttributePanickedHelp>,
417+
}
418+
419+
#[derive(Subdiagnostic)]
420+
#[help(expand_help)]
421+
pub(crate) struct CustomAttributePanickedHelp {
422+
pub message: String,
423+
}
424+
395425
#[derive(Diagnostic)]
396426
#[diag(expand_proc_macro_derive_tokens)]
397427
pub struct ProcMacroDeriveTokens {

compiler/rustc_expand/src/proc_macro.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@ impl base::AttrProcMacro for AttrProcMacro {
9393
let server = proc_macro_server::Rustc::new(ecx);
9494
self.client.run(&strategy, server, annotation, annotated, proc_macro_backtrace).map_err(
9595
|e| {
96-
let mut err = ecx.dcx().struct_span_err(span, "custom attribute panicked");
97-
if let Some(s) = e.as_str() {
98-
err.help(format!("message: {s}"));
99-
}
100-
err.emit()
96+
ecx.dcx().emit_err(errors::CustomAttributePanicked {
97+
span,
98+
message: e.as_str().map(|message| errors::CustomAttributePanickedHelp {
99+
message: message.into(),
100+
}),
101+
})
101102
},
102103
)
103104
}
@@ -146,11 +147,14 @@ impl MultiItemModifier for DeriveProcMacro {
146147
match self.client.run(&strategy, server, input, proc_macro_backtrace) {
147148
Ok(stream) => stream,
148149
Err(e) => {
149-
let mut err = ecx.dcx().struct_span_err(span, "proc-macro derive panicked");
150-
if let Some(s) = e.as_str() {
151-
err.help(format!("message: {s}"));
152-
}
153-
err.emit();
150+
ecx.dcx().emit_err({
151+
errors::ProcMacroDerivePanicked {
152+
span,
153+
message: e.as_str().map(|message| {
154+
errors::ProcMacroDerivePanickedHelp { message: message.into() }
155+
}),
156+
}
157+
});
154158
return ExpandResult::Ready(vec![]);
155159
}
156160
}

0 commit comments

Comments
 (0)