1
Fork 0

Move eager translation to a method on Diag

This will allow us to eagerly translate messages on a top-level
diagnostic, such as a `LintDiagnostic`. As a bonus, we can remove the
awkward closure passed into Subdiagnostic and make better use of
`Into`.
This commit is contained in:
Jake Goulding 2025-03-21 10:09:17 -04:00
parent 78f2104e33
commit 0117884917
20 changed files with 98 additions and 271 deletions

View file

@ -512,23 +512,17 @@ struct LocalLabel<'a> {
/// A custom `Subdiagnostic` implementation so that the notes are delivered in a specific order
impl Subdiagnostic for LocalLabel<'_> {
fn add_to_diag_with<
G: rustc_errors::EmissionGuarantee,
F: rustc_errors::SubdiagMessageOp<G>,
>(
self,
diag: &mut rustc_errors::Diag<'_, G>,
f: &F,
) {
fn add_to_diag<G: rustc_errors::EmissionGuarantee>(self, diag: &mut rustc_errors::Diag<'_, G>) {
diag.arg("name", self.name);
diag.arg("is_generated_name", self.is_generated_name);
diag.arg("is_dropped_first_edition_2024", self.is_dropped_first_edition_2024);
let msg = f(diag, crate::fluent_generated::mir_transform_tail_expr_local.into());
let msg = diag.eagerly_translate(crate::fluent_generated::mir_transform_tail_expr_local);
diag.span_label(self.span, msg);
for dtor in self.destructors {
dtor.add_to_diag_with(diag, f);
dtor.add_to_diag(diag);
}
let msg = f(diag, crate::fluent_generated::mir_transform_label_local_epilogue);
let msg =
diag.eagerly_translate(crate::fluent_generated::mir_transform_label_local_epilogue);
diag.span_label(self.span, msg);
}
}