Skip to content

Commit 99529b0

Browse files
authored
Rollup merge of #106549 - wcampbell0x2a:use-fmt-named-parameters-borrowck, r=estebank
Use fmt named parameters in rustc_borrowck
2 parents 357128a + d0cf7e3 commit 99529b0

9 files changed

+63
-92
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
156156
err.span_note(
157157
MultiSpan::from_spans(reinit_spans),
158158
&if reinits <= 3 {
159-
format!("these {} reinitializations might get skipped", reinits)
159+
format!("these {reinits} reinitializations might get skipped")
160160
} else {
161161
format!(
162162
"these 3 reinitializations and {} other{} might get skipped",
@@ -225,9 +225,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
225225
err.span_label(
226226
span,
227227
format!(
228-
"value {} here after {}move",
228+
"value {} here after {partial_str}move",
229229
desired_action.as_verb_in_past_tense(),
230-
partial_str
231230
),
232231
);
233232
}
@@ -257,7 +256,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
257256
&format!(
258257
"consider creating a fresh reborrow of {} here",
259258
self.describe_place(moved_place)
260-
.map(|n| format!("`{}`", n))
259+
.map(|n| format!("`{n}`"))
261260
.unwrap_or_else(|| "the mutable reference".to_string()),
262261
),
263262
"&mut *",
@@ -271,7 +270,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
271270
DescribePlaceOpt { including_downcast: true, including_tuple_field: true },
272271
);
273272
let note_msg = match opt_name {
274-
Some(name) => format!("`{}`", name),
273+
Some(name) => format!("`{name}`"),
275274
None => "value".to_owned(),
276275
};
277276
if self.suggest_borrow_fn_like(&mut err, ty, &move_site_vec, &note_msg) {
@@ -297,9 +296,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
297296
} = use_spans
298297
{
299298
err.note(&format!(
300-
"{} occurs due to deref coercion to `{}`",
299+
"{} occurs due to deref coercion to `{deref_target_ty}`",
301300
desired_action.as_noun(),
302-
deref_target_ty
303301
));
304302

305303
// Check first whether the source is accessible (issue #87060)

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+13-26
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
7777
if borrow_span.map(|sp| !sp.overlaps(var_or_use_span)).unwrap_or(true) {
7878
err.span_label(
7979
var_or_use_span,
80-
format!("{}borrow later {}", borrow_desc, message),
80+
format!("{borrow_desc}borrow later {message}"),
8181
);
8282
}
8383
} else {
@@ -90,7 +90,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
9090
let capture_kind_label = message;
9191
err.span_label(
9292
var_or_use_span,
93-
format!("{}borrow later {}", borrow_desc, capture_kind_label),
93+
format!("{borrow_desc}borrow later {capture_kind_label}"),
9494
);
9595
err.span_label(path_span, path_label);
9696
}
@@ -110,7 +110,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
110110
};
111111
// We can use `var_or_use_span` if either `path_span` is not present, or both spans are the same
112112
if path_span.map(|path_span| path_span == var_or_use_span).unwrap_or(true) {
113-
err.span_label(var_or_use_span, format!("{}{}", borrow_desc, message));
113+
err.span_label(var_or_use_span, format!("{borrow_desc}{message}"));
114114
} else {
115115
// path_span must be `Some` as otherwise the if condition is true
116116
let path_span = path_span.unwrap();
@@ -121,7 +121,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
121121
let capture_kind_label = message;
122122
err.span_label(
123123
var_or_use_span,
124-
format!("{}borrow later {}", borrow_desc, capture_kind_label),
124+
format!("{borrow_desc}borrow later {capture_kind_label}"),
125125
);
126126
err.span_label(path_span, path_label);
127127
}
@@ -160,12 +160,8 @@ impl<'tcx> BorrowExplanation<'tcx> {
160160
match local_names[dropped_local] {
161161
Some(local_name) if !local_decl.from_compiler_desugaring() => {
162162
let message = format!(
163-
"{B}borrow might be used here, when `{LOC}` is dropped \
164-
and runs the {DTOR} for {TYPE}",
165-
B = borrow_desc,
166-
LOC = local_name,
167-
TYPE = type_desc,
168-
DTOR = dtor_desc
163+
"{borrow_desc}borrow might be used here, when `{local_name}` is dropped \
164+
and runs the {dtor_desc} for {type_desc}",
169165
);
170166
err.span_label(body.source_info(drop_loc).span, message);
171167

@@ -180,18 +176,14 @@ impl<'tcx> BorrowExplanation<'tcx> {
180176
err.span_label(
181177
local_decl.source_info.span,
182178
format!(
183-
"a temporary with access to the {B}borrow \
179+
"a temporary with access to the {borrow_desc}borrow \
184180
is created here ...",
185-
B = borrow_desc
186181
),
187182
);
188183
let message = format!(
189-
"... and the {B}borrow might be used here, \
184+
"... and the {borrow_desc}borrow might be used here, \
190185
when that temporary is dropped \
191-
and runs the {DTOR} for {TYPE}",
192-
B = borrow_desc,
193-
TYPE = type_desc,
194-
DTOR = dtor_desc
186+
and runs the {dtor_desc} for {type_desc}",
195187
);
196188
err.span_label(body.source_info(drop_loc).span, message);
197189

@@ -249,20 +241,16 @@ impl<'tcx> BorrowExplanation<'tcx> {
249241
err.span_label(
250242
span,
251243
format!(
252-
"{}requires that `{}` is borrowed for `{}`",
244+
"{}requires that `{desc}` is borrowed for `{region_name}`",
253245
category.description(),
254-
desc,
255-
region_name,
256246
),
257247
);
258248
} else {
259249
err.span_label(
260250
span,
261251
format!(
262-
"{}requires that {}borrow lasts for `{}`",
252+
"{}requires that {borrow_desc}borrow lasts for `{region_name}`",
263253
category.description(),
264-
borrow_desc,
265-
region_name,
266254
),
267255
);
268256
};
@@ -296,15 +284,14 @@ impl<'tcx> BorrowExplanation<'tcx> {
296284
if region_name.was_named() { region_name.name } else { kw::UnderscoreLifetime };
297285

298286
let msg = format!(
299-
"you can add a bound to the {}to make it last less than `'static` and match `{}`",
287+
"you can add a bound to the {}to make it last less than `'static` and match `{region_name}`",
300288
category.description(),
301-
region_name,
302289
);
303290

304291
err.span_suggestion_verbose(
305292
span.shrink_to_hi(),
306293
&msg,
307-
format!(" + {}", suggestable_name),
294+
format!(" + {suggestable_name}"),
308295
Applicability::Unspecified,
309296
);
310297
}

compiler/rustc_borrowck/src/diagnostics/mod.rs

+16-22
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
403403
move_prefix: &str,
404404
) {
405405
let message = format!(
406-
"{}move occurs because {} has type `{}`, which does not implement the `Copy` trait",
407-
move_prefix, place_desc, ty,
406+
"{move_prefix}move occurs because {place_desc} has type `{ty}`, which does not implement the `Copy` trait",
408407
);
409408
if let Some(span) = span {
410409
err.span_label(span, message);
@@ -739,11 +738,11 @@ impl<'tcx> BorrowedContentSource<'tcx> {
739738
BorrowedContentSource::OverloadedDeref(ty) => ty
740739
.ty_adt_def()
741740
.and_then(|adt| match tcx.get_diagnostic_name(adt.did())? {
742-
name @ (sym::Rc | sym::Arc) => Some(format!("an `{}`", name)),
741+
name @ (sym::Rc | sym::Arc) => Some(format!("an `{name}`")),
743742
_ => None,
744743
})
745-
.unwrap_or_else(|| format!("dereference of `{}`", ty)),
746-
BorrowedContentSource::OverloadedIndex(ty) => format!("index of `{}`", ty),
744+
.unwrap_or_else(|| format!("dereference of `{ty}`")),
745+
BorrowedContentSource::OverloadedIndex(ty) => format!("index of `{ty}`"),
747746
}
748747
}
749748

@@ -769,11 +768,11 @@ impl<'tcx> BorrowedContentSource<'tcx> {
769768
BorrowedContentSource::OverloadedDeref(ty) => ty
770769
.ty_adt_def()
771770
.and_then(|adt| match tcx.get_diagnostic_name(adt.did())? {
772-
name @ (sym::Rc | sym::Arc) => Some(format!("an `{}`", name)),
771+
name @ (sym::Rc | sym::Arc) => Some(format!("an `{name}`")),
773772
_ => None,
774773
})
775-
.unwrap_or_else(|| format!("dereference of `{}`", ty)),
776-
BorrowedContentSource::OverloadedIndex(ty) => format!("an index of `{}`", ty),
774+
.unwrap_or_else(|| format!("dereference of `{ty}`")),
775+
BorrowedContentSource::OverloadedIndex(ty) => format!("an index of `{ty}`"),
777776
}
778777
}
779778

@@ -1033,7 +1032,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10331032
if let UseSpans::FnSelfUse { var_span, fn_call_span, fn_span, kind } = move_spans {
10341033
let place_name = self
10351034
.describe_place(moved_place.as_ref())
1036-
.map(|n| format!("`{}`", n))
1035+
.map(|n| format!("`{n}`"))
10371036
.unwrap_or_else(|| "value".to_owned());
10381037
match kind {
10391038
CallKind::FnCall { fn_trait_id, .. }
@@ -1042,8 +1041,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10421041
err.span_label(
10431042
fn_call_span,
10441043
&format!(
1045-
"{} {}moved due to this call{}",
1046-
place_name, partially_str, loop_message
1044+
"{place_name} {partially_str}moved due to this call{loop_message}",
10471045
),
10481046
);
10491047
err.span_note(
@@ -1056,8 +1054,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10561054
err.span_label(
10571055
fn_call_span,
10581056
&format!(
1059-
"{} {}moved due to usage in operator{}",
1060-
place_name, partially_str, loop_message
1057+
"{place_name} {partially_str}moved due to usage in operator{loop_message}",
10611058
),
10621059
);
10631060
if self.fn_self_span_reported.insert(fn_span) {
@@ -1089,9 +1086,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10891086
err.span_suggestion_verbose(
10901087
move_span.shrink_to_lo(),
10911088
&format!(
1092-
"consider iterating over a slice of the `{}`'s content to \
1089+
"consider iterating over a slice of the `{ty}`'s content to \
10931090
avoid moving into the `for` loop",
1094-
ty,
10951091
),
10961092
"&",
10971093
Applicability::MaybeIncorrect,
@@ -1101,8 +1097,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11011097
err.span_label(
11021098
fn_call_span,
11031099
&format!(
1104-
"{} {}moved due to this implicit call to `.into_iter()`{}",
1105-
place_name, partially_str, loop_message
1100+
"{place_name} {partially_str}moved due to this implicit call to `.into_iter()`{loop_message}",
11061101
),
11071102
);
11081103
// If the moved place was a `&mut` ref, then we can
@@ -1118,7 +1113,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11181113
&format!(
11191114
"consider creating a fresh reborrow of {} here",
11201115
self.describe_place(moved_place.as_ref())
1121-
.map(|n| format!("`{}`", n))
1116+
.map(|n| format!("`{n}`"))
11221117
.unwrap_or_else(|| "the mutable reference".to_string()),
11231118
),
11241119
"&mut *",
@@ -1130,8 +1125,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11301125
err.span_label(
11311126
fn_call_span,
11321127
&format!(
1133-
"{} {}moved due to this method call{}",
1134-
place_name, partially_str, loop_message
1128+
"{place_name} {partially_str}moved due to this method call{loop_message}",
11351129
),
11361130
);
11371131
let infcx = tcx.infer_ctxt().build();
@@ -1206,15 +1200,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12061200
if move_span != span || !loop_message.is_empty() {
12071201
err.span_label(
12081202
move_span,
1209-
format!("value {}moved{} here{}", partially_str, move_msg, loop_message),
1203+
format!("value {partially_str}moved{move_msg} here{loop_message}"),
12101204
);
12111205
}
12121206
// If the move error occurs due to a loop, don't show
12131207
// another message for the same span
12141208
if loop_message.is_empty() {
12151209
move_spans.var_span_label(
12161210
err,
1217-
format!("variable {}moved due to use{}", partially_str, move_spans.describe()),
1211+
format!("variable {partially_str}moved due to use{}", move_spans.describe()),
12181212
"moved",
12191213
);
12201214
}

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
264264
ProjectionElem::Deref,
265265
],
266266
} => {
267-
err.span_label(span, format!("cannot {ACT}", ACT = act));
267+
err.span_label(span, format!("cannot {act}"));
268268

269269
if let Some(span) = get_mut_span_in_struct_field(
270270
self.infcx.tcx,
@@ -290,7 +290,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
290290
.unwrap_or(false) =>
291291
{
292292
let decl = &self.body.local_decls[local];
293-
err.span_label(span, format!("cannot {ACT}", ACT = act));
293+
err.span_label(span, format!("cannot {act}"));
294294
if let Some(mir::Statement {
295295
source_info,
296296
kind:
@@ -639,7 +639,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
639639
}
640640

641641
PlaceRef { local: _, projection: [.., ProjectionElem::Deref] } => {
642-
err.span_label(span, format!("cannot {ACT}", ACT = act));
642+
err.span_label(span, format!("cannot {act}"));
643643

644644
match opt_source {
645645
Some(BorrowedContentSource::OverloadedDeref(ty)) => {
@@ -1212,7 +1212,7 @@ fn suggest_ampmut<'tcx>(
12121212
{
12131213
let lt_name = &src[1..ws_pos];
12141214
let ty = &src[ws_pos..];
1215-
return (true, highlight_span, format!("&{} mut{}", lt_name, ty));
1215+
return (true, highlight_span, format!("&{lt_name} mut{ty}"));
12161216
}
12171217

12181218
let ty_mut = local_decl.ty.builtin_deref(true).unwrap();

compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,14 @@ impl OutlivesSuggestionBuilder {
209209
let mut diag = if suggested.len() == 1 {
210210
mbcx.infcx.tcx.sess.diagnostic().struct_help(&match suggested.last().unwrap() {
211211
SuggestedConstraint::Outlives(a, bs) => {
212-
let bs: SmallVec<[String; 2]> = bs.iter().map(|r| format!("{}", r)).collect();
213-
format!("add bound `{}: {}`", a, bs.join(" + "))
212+
let bs: SmallVec<[String; 2]> = bs.iter().map(|r| r.to_string()).collect();
213+
format!("add bound `{a}: {}`", bs.join(" + "))
214214
}
215215

216216
SuggestedConstraint::Equal(a, b) => {
217-
format!("`{}` and `{}` must be the same: replace one with the other", a, b)
217+
format!("`{a}` and `{b}` must be the same: replace one with the other")
218218
}
219-
SuggestedConstraint::Static(a) => format!("replace `{}` with `'static`", a),
219+
SuggestedConstraint::Static(a) => format!("replace `{a}` with `'static`"),
220220
})
221221
} else {
222222
// Create a new diagnostic.
@@ -231,18 +231,16 @@ impl OutlivesSuggestionBuilder {
231231
for constraint in suggested {
232232
match constraint {
233233
SuggestedConstraint::Outlives(a, bs) => {
234-
let bs: SmallVec<[String; 2]> =
235-
bs.iter().map(|r| format!("{}", r)).collect();
236-
diag.help(&format!("add bound `{}: {}`", a, bs.join(" + ")));
234+
let bs: SmallVec<[String; 2]> = bs.iter().map(|r| r.to_string()).collect();
235+
diag.help(&format!("add bound `{a}: {}`", bs.join(" + ")));
237236
}
238237
SuggestedConstraint::Equal(a, b) => {
239238
diag.help(&format!(
240-
"`{}` and `{}` must be the same: replace one with the other",
241-
a, b
239+
"`{a}` and `{b}` must be the same: replace one with the other",
242240
));
243241
}
244242
SuggestedConstraint::Static(a) => {
245-
diag.help(&format!("replace `{}` with `'static`", a));
243+
diag.help(&format!("replace `{a}` with `'static`"));
246244
}
247245
}
248246
}

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
422422
);
423423
(desc, note)
424424
}
425-
_ => panic!("Unexpected type {:?}", ty),
425+
_ => panic!("Unexpected type {ty:?}"),
426426
};
427427
diag.note(&format!("requirement occurs because of {desc}",));
428428
diag.note(&note);
@@ -725,10 +725,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
725725
let lifetime = if f.has_name() { fr_name.name } else { kw::UnderscoreLifetime };
726726

727727
let arg = match param.param.pat.simple_ident() {
728-
Some(simple_ident) => format!("argument `{}`", simple_ident),
728+
Some(simple_ident) => format!("argument `{simple_ident}`"),
729729
None => "the argument".to_string(),
730730
};
731-
let captures = format!("captures data from {}", arg);
731+
let captures = format!("captures data from {arg}");
732732

733733
return nice_region_error::suggest_new_region_bound(
734734
self.infcx.tcx,

0 commit comments

Comments
 (0)