Rollup merge of #155822 - mejrs:default_fmt_args, r=JonathanBrouwer

Add default field values to diagnostic FormatArgs

This type has a decent amount of unused fields (and I am planning to add more).
This commit is contained in:
Jonathan Brouwer
2026-04-26 19:06:32 +02:00
committed by GitHub
6 changed files with 9 additions and 29 deletions
@@ -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);
+1
View File
@@ -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)]
+1 -12
View File
@@ -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()
};
+4 -3
View File
@@ -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)]
+1
View File
@@ -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)]
+1 -6
View File
@@ -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);