Skip to content

Commit 139bcba

Browse files
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).
2 parents ae77516 + 48fe89f commit 139bcba

6 files changed

Lines changed: 9 additions & 29 deletions

File tree

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
156156
.collect();
157157
generic_args.push((kw::SelfUpper, this.clone()));
158158

159-
let args = FormatArgs {
160-
this,
161-
// Unused
162-
this_sugared: String::new(),
163-
// Unused
164-
item_context: "",
165-
generic_args,
166-
};
159+
let args = FormatArgs { this, generic_args, .. };
167160
let CustomDiagnostic { message, label, notes, parent_label: _ } =
168161
directive.eval(None, &args);
169162

compiler/rustc_expand/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// tidy-alphabetical-start
22
#![allow(internal_features)]
33
#![feature(associated_type_defaults)]
4+
#![feature(default_field_values)]
45
#![feature(macro_metavar_expr)]
56
#![feature(proc_macro_diagnostic)]
67
#![feature(proc_macro_internals)]

compiler/rustc_expand/src/mbe/diagnostics.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,8 @@ pub(super) fn failed_to_match_macro(
7777
let CustomDiagnostic {
7878
message: custom_message, label: custom_label, notes: custom_notes, ..
7979
} = {
80-
let macro_name = name.to_string();
8180
on_unmatch_args
82-
.map(|directive| {
83-
directive.eval(
84-
None,
85-
&FormatArgs {
86-
this: macro_name.clone(),
87-
this_sugared: macro_name,
88-
item_context: "macro invocation",
89-
generic_args: Vec::new(),
90-
},
91-
)
92-
})
81+
.map(|directive| directive.eval(None, &FormatArgs { this: name.to_string(), .. }))
9382
.unwrap_or_default()
9483
};
9584

compiler/rustc_hir/src/attrs/diagnostic.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,11 @@ impl FormatString {
218218
/// ```
219219
#[derive(Debug)]
220220
pub struct FormatArgs {
221+
/// The name of the item the attribute is on.
221222
pub this: String,
222-
pub this_sugared: String,
223-
pub item_context: &'static str,
224-
pub generic_args: Vec<(Symbol, String)>,
223+
pub this_sugared: String = String::new(),
224+
pub item_context: &'static str = "",
225+
pub generic_args: Vec<(Symbol, String)> = Vec::new(),
225226
}
226227

227228
#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)]

compiler/rustc_hir/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![feature(closure_track_caller)]
88
#![feature(const_default)]
99
#![feature(const_trait_impl)]
10+
#![feature(default_field_values)]
1011
#![feature(derive_const)]
1112
#![feature(exhaustive_patterns)]
1213
#![feature(never_type)]

compiler/rustc_resolve/src/imports.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -886,12 +886,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
886886

887887
let args = FormatArgs {
888888
this,
889-
// Unused
890-
this_sugared: String::new(),
891-
// Unused
892-
item_context: "",
893-
// Unused
894-
generic_args: Vec::new(),
889+
..
895890
};
896891
let CustomDiagnostic { message, label, notes, .. } = directive.eval(None, &args);
897892

0 commit comments

Comments
 (0)