Rollup merge of #121288 - tshepang:make-expand-translatable, r=michaelwoerister

make rustc_expand translatable

these are the last of the easy ones
This commit is contained in:
Dylan DPC 2024-02-21 08:55:56 +00:00 committed by GitHub
commit 4840785cf8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 52 additions and 10 deletions

View file

@ -392,6 +392,36 @@ 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 {
#[primary_span]
pub span: Span,
#[subdiagnostic]
pub message: Option<CustomAttributePanickedHelp>,
}
#[derive(Subdiagnostic)]
#[help(expand_help)]
pub(crate) struct CustomAttributePanickedHelp {
pub message: String,
}
#[derive(Diagnostic)]
#[diag(expand_proc_macro_derive_tokens)]
pub struct ProcMacroDeriveTokens {

View file

@ -93,11 +93,12 @@ impl base::AttrProcMacro for AttrProcMacro {
let server = proc_macro_server::Rustc::new(ecx);
self.client.run(&strategy, server, annotation, annotated, proc_macro_backtrace).map_err(
|e| {
let mut err = ecx.dcx().struct_span_err(span, "custom attribute panicked");
if let Some(s) = e.as_str() {
err.help(format!("message: {s}"));
}
err.emit()
ecx.dcx().emit_err(errors::CustomAttributePanicked {
span,
message: e.as_str().map(|message| errors::CustomAttributePanickedHelp {
message: message.into(),
}),
})
},
)
}
@ -146,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![]);
}
}