From 48fe89f9941ba0b79618e44e0176909ad85decb7 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Sun, 26 Apr 2026 14:23:53 +0200 Subject: [PATCH] add default field values to diagnostic FormatArgs --- .../src/diagnostics/conflict_errors.rs | 9 +-------- compiler/rustc_expand/src/lib.rs | 1 + compiler/rustc_expand/src/mbe/diagnostics.rs | 13 +------------ compiler/rustc_hir/src/attrs/diagnostic.rs | 7 ++++--- compiler/rustc_hir/src/lib.rs | 1 + compiler/rustc_resolve/src/imports.rs | 7 +------ 6 files changed, 9 insertions(+), 29 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 2735c800c4a3..f7d35f3ff3b4 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -156,14 +156,7 @@ pub(crate) fn report_use_of_moved_or_uninitialized( .collect(); generic_args.push((kw::SelfUpper, this.clone())); - let args = FormatArgs { - this, - // Unused - this_sugared: String::new(), - // Unused - item_context: "", - generic_args, - }; + let args = FormatArgs { this, generic_args, .. }; let CustomDiagnostic { message, label, notes, parent_label: _ } = directive.eval(None, &args); diff --git a/compiler/rustc_expand/src/lib.rs b/compiler/rustc_expand/src/lib.rs index d2ac7103bccb..5068501a0e2d 100644 --- a/compiler/rustc_expand/src/lib.rs +++ b/compiler/rustc_expand/src/lib.rs @@ -1,6 +1,7 @@ // tidy-alphabetical-start #![allow(internal_features)] #![feature(associated_type_defaults)] +#![feature(default_field_values)] #![feature(macro_metavar_expr)] #![feature(proc_macro_diagnostic)] #![feature(proc_macro_internals)] diff --git a/compiler/rustc_expand/src/mbe/diagnostics.rs b/compiler/rustc_expand/src/mbe/diagnostics.rs index 4e7e51c0a43c..16b21b062cce 100644 --- a/compiler/rustc_expand/src/mbe/diagnostics.rs +++ b/compiler/rustc_expand/src/mbe/diagnostics.rs @@ -77,19 +77,8 @@ pub(super) fn failed_to_match_macro( let CustomDiagnostic { message: custom_message, label: custom_label, notes: custom_notes, .. } = { - let macro_name = name.to_string(); on_unmatch_args - .map(|directive| { - directive.eval( - None, - &FormatArgs { - this: macro_name.clone(), - this_sugared: macro_name, - item_context: "macro invocation", - generic_args: Vec::new(), - }, - ) - }) + .map(|directive| directive.eval(None, &FormatArgs { this: name.to_string(), .. })) .unwrap_or_default() }; diff --git a/compiler/rustc_hir/src/attrs/diagnostic.rs b/compiler/rustc_hir/src/attrs/diagnostic.rs index 66cdf2be8fc4..2beafee54541 100644 --- a/compiler/rustc_hir/src/attrs/diagnostic.rs +++ b/compiler/rustc_hir/src/attrs/diagnostic.rs @@ -218,10 +218,11 @@ fn visit_params(&self, visit: &mut impl FnMut(Symbol, Span)) { /// ``` #[derive(Debug)] pub struct FormatArgs { + /// The name of the item the attribute is on. pub this: String, - pub this_sugared: String, - pub item_context: &'static str, - pub generic_args: Vec<(Symbol, String)>, + pub this_sugared: String = String::new(), + pub item_context: &'static str = "", + pub generic_args: Vec<(Symbol, String)> = Vec::new(), } #[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)] diff --git a/compiler/rustc_hir/src/lib.rs b/compiler/rustc_hir/src/lib.rs index c2d9f879cd60..7c2bf3c5b279 100644 --- a/compiler/rustc_hir/src/lib.rs +++ b/compiler/rustc_hir/src/lib.rs @@ -7,6 +7,7 @@ #![feature(closure_track_caller)] #![feature(const_default)] #![feature(const_trait_impl)] +#![feature(default_field_values)] #![feature(derive_const)] #![feature(exhaustive_patterns)] #![feature(never_type)] diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 198ec4080816..b6ba35f0f3db 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -886,12 +886,7 @@ fn throw_unresolved_import_error( let args = FormatArgs { this, - // Unused - this_sugared: String::new(), - // Unused - item_context: "", - // Unused - generic_args: Vec::new(), + .. }; let CustomDiagnostic { message, label, notes, .. } = directive.eval(None, &args);