Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ece6b97

Browse files
authoredApr 9, 2022
Rollup merge of #95810 - TaKO8Ki:use-format-args-capture-and-remove-unnecessary-nesting-in-rustc-borrowck, r=davidtwco
Use `format-args-capture` and remove unnecessary nested blocks
2 parents af895b0 + 470b4fc commit ece6b97

File tree

5 files changed

+116
-133
lines changed

5 files changed

+116
-133
lines changed
 

‎compiler/rustc_borrowck/src/diagnostics/move_errors.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
157157
// Error with the match place
158158
LookupResult::Parent(_) => {
159159
for ge in &mut *grouped_errors {
160-
if let GroupedMoveError::MovesFromPlace { span, binds_to, .. } = ge {
161-
if match_span == *span {
162-
debug!("appending local({:?}) to list", bind_to);
163-
if !binds_to.is_empty() {
164-
binds_to.push(bind_to);
165-
}
166-
return;
160+
if let GroupedMoveError::MovesFromPlace { span, binds_to, .. } = ge
161+
&& match_span == *span
162+
{
163+
debug!("appending local({:?}) to list", bind_to);
164+
if !binds_to.is_empty() {
165+
binds_to.push(bind_to);
167166
}
167+
return;
168168
}
169169
}
170170
debug!("found a new move error location");
@@ -353,7 +353,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
353353
None => bug!("closure kind not inferred by borrowck"),
354354
};
355355
let capture_description =
356-
format!("captured variable in an `{}` closure", closure_kind);
356+
format!("captured variable in an `{closure_kind}` closure");
357357

358358
let upvar = &self.upvars[upvar_field.unwrap().index()];
359359
let upvar_hir_id = upvar.place.get_root_variable();
@@ -364,9 +364,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
364364

365365
let place_description =
366366
if self.is_upvar_field_projection(move_place.as_ref()).is_some() {
367-
format!("{}, a {}", place_name, capture_description)
367+
format!("{place_name}, a {capture_description}")
368368
} else {
369-
format!("{}, as `{}` is a {}", place_name, upvar_name, capture_description)
369+
format!("{place_name}, as `{upvar_name}` is a {capture_description}")
370370
};
371371

372372
debug!(
@@ -379,7 +379,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
379379
diag.span_label(upvar_span, "captured outer variable");
380380
diag.span_label(
381381
self.body.span,
382-
format!("captured by this `{}` closure", closure_kind),
382+
format!("captured by this `{closure_kind}` closure"),
383383
);
384384

385385
diag
@@ -390,7 +390,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
390390
{
391391
(Some(place_desc), Some(source_desc)) => self.cannot_move_out_of(
392392
span,
393-
&format!("`{}` which is behind a {}", place_desc, source_desc),
393+
&format!("`{place_desc}` which is behind a {source_desc}"),
394394
),
395395
(_, _) => self.cannot_move_out_of(
396396
span,
@@ -435,15 +435,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
435435
err.span_suggestion(
436436
span,
437437
"consider borrowing here",
438-
format!("&{}", snippet),
438+
format!("&{snippet}"),
439439
Applicability::Unspecified,
440440
);
441441
}
442442

443443
if binds_to.is_empty() {
444444
let place_ty = move_from.ty(self.body, self.infcx.tcx).ty;
445445
let place_desc = match self.describe_place(move_from.as_ref()) {
446-
Some(desc) => format!("`{}`", desc),
446+
Some(desc) => format!("`{desc}`"),
447447
None => "value".to_string(),
448448
};
449449

@@ -472,12 +472,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
472472
let span = use_spans.var_or_use();
473473
let place_ty = original_path.ty(self.body, self.infcx.tcx).ty;
474474
let place_desc = match self.describe_place(original_path.as_ref()) {
475-
Some(desc) => format!("`{}`", desc),
475+
Some(desc) => format!("`{desc}`"),
476476
None => "value".to_string(),
477477
};
478478
self.note_type_does_not_implement_copy(err, &place_desc, place_ty, Some(span), "");
479479

480-
use_spans.args_span_label(err, format!("move out of {} occurs here", place_desc));
480+
use_spans.args_span_label(err, format!("move out of {place_desc} occurs here"));
481481
}
482482
}
483483
}
@@ -511,7 +511,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
511511
for (span, to_remove, suggestion) in suggestions {
512512
err.span_suggestion(
513513
span,
514-
&format!("consider removing the `{}`", to_remove),
514+
&format!("consider removing the `{to_remove}`"),
515515
suggestion,
516516
Applicability::MachineApplicable,
517517
);

‎compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 72 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
5555
reason = ", as it is not declared as mutable".to_string();
5656
} else {
5757
let name = self.local_names[local].expect("immutable unnamed local");
58-
reason = format!(", as `{}` is not declared as mutable", name);
58+
reason = format!(", as `{name}` is not declared as mutable");
5959
}
6060
}
6161

@@ -88,7 +88,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
8888
reason = ", as it is not declared as mutable".to_string();
8989
} else {
9090
let name = self.upvars[upvar_index.index()].place.to_string(self.infcx.tcx);
91-
reason = format!(", as `{}` is not declared as mutable", name);
91+
reason = format!(", as `{name}` is not declared as mutable");
9292
}
9393
}
9494
}
@@ -103,14 +103,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
103103
if self.body.local_decls[local].is_ref_to_static() =>
104104
{
105105
if access_place.projection.len() == 1 {
106-
item_msg = format!("immutable static item {}", access_place_desc);
106+
item_msg = format!("immutable static item {access_place_desc}");
107107
reason = String::new();
108108
} else {
109109
item_msg = access_place_desc;
110110
let local_info = &self.body.local_decls[local].local_info;
111111
if let Some(box LocalInfo::StaticRef { def_id, .. }) = *local_info {
112112
let static_name = &self.infcx.tcx.item_name(def_id);
113-
reason = format!(", as `{}` is an immutable static item", static_name);
113+
reason = format!(", as `{static_name}` is an immutable static item");
114114
} else {
115115
bug!("is_ref_to_static return true, but not ref to static?");
116116
}
@@ -148,15 +148,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
148148
let pointer_type = source.describe_for_immutable_place(self.infcx.tcx);
149149
opt_source = Some(source);
150150
if let Some(desc) = self.describe_place(access_place.as_ref()) {
151-
item_msg = format!("`{}`", desc);
151+
item_msg = format!("`{desc}`");
152152
reason = match error_access {
153-
AccessKind::Mutate => format!(", which is behind {}", pointer_type),
153+
AccessKind::Mutate => format!(", which is behind {pointer_type}"),
154154
AccessKind::MutableBorrow => {
155-
format!(", as it is behind {}", pointer_type)
155+
format!(", as it is behind {pointer_type}")
156156
}
157157
}
158158
} else {
159-
item_msg = format!("data in {}", pointer_type);
159+
item_msg = format!("data in {pointer_type}");
160160
reason = String::new();
161161
}
162162
}
@@ -362,29 +362,27 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
362362

363363
let upvar_hir_id = captured_place.get_root_variable();
364364

365-
if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find(upvar_hir_id) {
366-
if let hir::PatKind::Binding(
365+
if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find(upvar_hir_id)
366+
&& let hir::PatKind::Binding(
367367
hir::BindingAnnotation::Unannotated,
368368
_,
369369
upvar_ident,
370370
_,
371371
) = pat.kind
372-
{
373-
err.span_suggestion(
374-
upvar_ident.span,
375-
"consider changing this to be mutable",
376-
format!("mut {}", upvar_ident.name),
377-
Applicability::MachineApplicable,
378-
);
379-
}
372+
{
373+
err.span_suggestion(
374+
upvar_ident.span,
375+
"consider changing this to be mutable",
376+
format!("mut {}", upvar_ident.name),
377+
Applicability::MachineApplicable,
378+
);
380379
}
381380

382381
let tcx = self.infcx.tcx;
383382
if let ty::Ref(_, ty, Mutability::Mut) = the_place_err.ty(self.body, tcx).ty.kind()
383+
&& let ty::Closure(id, _) = *ty.kind()
384384
{
385-
if let ty::Closure(id, _) = *ty.kind() {
386-
self.show_mutating_upvar(tcx, id, the_place_err, &mut err);
387-
}
385+
self.show_mutating_upvar(tcx, id, the_place_err, &mut err);
388386
}
389387
}
390388

@@ -544,8 +542,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
544542
err.span_suggestion(
545543
err_help_span,
546544
&format!(
547-
"consider changing this to be a mutable {}",
548-
pointer_desc
545+
"consider changing this to be a mutable {pointer_desc}"
549546
),
550547
suggested_code,
551548
Applicability::MachineApplicable,
@@ -554,8 +551,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
554551
err.span_suggestion(
555552
x,
556553
&format!(
557-
"consider changing that to be a mutable {}",
558-
pointer_desc
554+
"consider changing that to be a mutable {pointer_desc}"
559555
),
560556
suggested_code,
561557
Applicability::MachineApplicable,
@@ -606,15 +602,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
606602
Some(BorrowedContentSource::OverloadedDeref(ty)) => {
607603
err.help(&format!(
608604
"trait `DerefMut` is required to modify through a dereference, \
609-
but it is not implemented for `{}`",
610-
ty,
605+
but it is not implemented for `{ty}`",
611606
));
612607
}
613608
Some(BorrowedContentSource::OverloadedIndex(ty)) => {
614609
err.help(&format!(
615610
"trait `IndexMut` is required to modify indexed content, \
616-
but it is not implemented for `{}`",
617-
ty,
611+
but it is not implemented for `{ty}`",
618612
));
619613
}
620614
_ => (),
@@ -724,18 +718,18 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
724718
ty::UpvarCapture::ByRef(
725719
ty::BorrowKind::MutBorrow | ty::BorrowKind::UniqueImmBorrow,
726720
) => {
727-
capture_reason = format!("mutable borrow of `{}`", upvar);
721+
capture_reason = format!("mutable borrow of `{upvar}`");
728722
}
729723
ty::UpvarCapture::ByValue => {
730-
capture_reason = format!("possible mutation of `{}`", upvar);
724+
capture_reason = format!("possible mutation of `{upvar}`");
731725
}
732-
_ => bug!("upvar `{}` borrowed, but not mutably", upvar),
726+
_ => bug!("upvar `{upvar}` borrowed, but not mutably"),
733727
}
734728
break;
735729
}
736730
}
737731
if capture_reason.is_empty() {
738-
bug!("upvar `{}` borrowed, but cannot find reason", upvar);
732+
bug!("upvar `{upvar}` borrowed, but cannot find reason");
739733
}
740734
capture_reason
741735
} else {
@@ -829,27 +823,27 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
829823
.as_str()
830824
.starts_with(&original_method_ident.name.to_string())
831825
})
832-
.map(|ident| format!("{}()", ident))
826+
.map(|ident| format!("{ident}()"))
833827
.peekable()
834828
});
835829

836-
if let Some(mut suggestions) = opt_suggestions {
837-
if suggestions.peek().is_some() {
838-
err.span_suggestions(
839-
*span,
840-
"use mutable method",
841-
suggestions,
842-
Applicability::MaybeIncorrect,
843-
);
844-
}
830+
if let Some(mut suggestions) = opt_suggestions
831+
&& suggestions.peek().is_some()
832+
{
833+
err.span_suggestions(
834+
*span,
835+
"use mutable method",
836+
suggestions,
837+
Applicability::MaybeIncorrect,
838+
);
845839
}
846840
}
847841
};
848842
}
849843

850844
/// Targeted error when encountering an `FnMut` closure where an `Fn` closure was expected.
851845
fn expected_fn_found_fn_mut_call(&self, err: &mut Diagnostic, sp: Span, act: &str) {
852-
err.span_label(sp, format!("cannot {}", act));
846+
err.span_label(sp, format!("cannot {act}"));
853847

854848
let hir = self.infcx.tcx.hir();
855849
let closure_id = self.mir_hir_id();
@@ -1011,35 +1005,35 @@ fn suggest_ampmut<'tcx>(
10111005
opt_assignment_rhs_span: Option<Span>,
10121006
opt_ty_info: Option<Span>,
10131007
) -> (Span, String) {
1014-
if let Some(assignment_rhs_span) = opt_assignment_rhs_span {
1015-
if let Ok(src) = tcx.sess.source_map().span_to_snippet(assignment_rhs_span) {
1016-
let is_mutbl = |ty: &str| -> bool {
1017-
if let Some(rest) = ty.strip_prefix("mut") {
1018-
match rest.chars().next() {
1019-
// e.g. `&mut x`
1020-
Some(c) if c.is_whitespace() => true,
1021-
// e.g. `&mut(x)`
1022-
Some('(') => true,
1023-
// e.g. `&mut{x}`
1024-
Some('{') => true,
1025-
// e.g. `&mutablevar`
1026-
_ => false,
1027-
}
1028-
} else {
1029-
false
1030-
}
1031-
};
1032-
if let (true, Some(ws_pos)) = (src.starts_with("&'"), src.find(char::is_whitespace)) {
1033-
let lt_name = &src[1..ws_pos];
1034-
let ty = src[ws_pos..].trim_start();
1035-
if !is_mutbl(ty) {
1036-
return (assignment_rhs_span, format!("&{} mut {}", lt_name, ty));
1037-
}
1038-
} else if let Some(stripped) = src.strip_prefix('&') {
1039-
let stripped = stripped.trim_start();
1040-
if !is_mutbl(stripped) {
1041-
return (assignment_rhs_span, format!("&mut {}", stripped));
1008+
if let Some(assignment_rhs_span) = opt_assignment_rhs_span
1009+
&& let Ok(src) = tcx.sess.source_map().span_to_snippet(assignment_rhs_span)
1010+
{
1011+
let is_mutbl = |ty: &str| -> bool {
1012+
if let Some(rest) = ty.strip_prefix("mut") {
1013+
match rest.chars().next() {
1014+
// e.g. `&mut x`
1015+
Some(c) if c.is_whitespace() => true,
1016+
// e.g. `&mut(x)`
1017+
Some('(') => true,
1018+
// e.g. `&mut{x}`
1019+
Some('{') => true,
1020+
// e.g. `&mutablevar`
1021+
_ => false,
10421022
}
1023+
} else {
1024+
false
1025+
}
1026+
};
1027+
if let (true, Some(ws_pos)) = (src.starts_with("&'"), src.find(char::is_whitespace)) {
1028+
let lt_name = &src[1..ws_pos];
1029+
let ty = src[ws_pos..].trim_start();
1030+
if !is_mutbl(ty) {
1031+
return (assignment_rhs_span, format!("&{lt_name} mut {ty}"));
1032+
}
1033+
} else if let Some(stripped) = src.strip_prefix('&') {
1034+
let stripped = stripped.trim_start();
1035+
if !is_mutbl(stripped) {
1036+
return (assignment_rhs_span, format!("&mut {stripped}"));
10431037
}
10441038
}
10451039
}
@@ -1054,12 +1048,12 @@ fn suggest_ampmut<'tcx>(
10541048
None => local_decl.source_info.span,
10551049
};
10561050

1057-
if let Ok(src) = tcx.sess.source_map().span_to_snippet(highlight_span) {
1058-
if let (true, Some(ws_pos)) = (src.starts_with("&'"), src.find(char::is_whitespace)) {
1059-
let lt_name = &src[1..ws_pos];
1060-
let ty = &src[ws_pos..];
1061-
return (highlight_span, format!("&{} mut{}", lt_name, ty));
1062-
}
1051+
if let Ok(src) = tcx.sess.source_map().span_to_snippet(highlight_span)
1052+
&& let (true, Some(ws_pos)) = (src.starts_with("&'"), src.find(char::is_whitespace))
1053+
{
1054+
let lt_name = &src[1..ws_pos];
1055+
let ty = &src[ws_pos..];
1056+
return (highlight_span, format!("&{} mut{}", lt_name, ty));
10631057
}
10641058

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

‎compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,12 @@ impl OutlivesSuggestionBuilder {
168168
let fr_name = self.region_vid_to_name(mbcx, errci.fr);
169169
let outlived_fr_name = self.region_vid_to_name(mbcx, errci.outlived_fr);
170170

171-
if let (Some(fr_name), Some(outlived_fr_name)) = (fr_name, outlived_fr_name) {
172-
if !matches!(outlived_fr_name.source, RegionNameSource::Static) {
173-
diag.help(&format!(
174-
"consider adding the following bound: `{}: {}`",
175-
fr_name, outlived_fr_name
176-
));
177-
}
171+
if let (Some(fr_name), Some(outlived_fr_name)) = (fr_name, outlived_fr_name)
172+
&& !matches!(outlived_fr_name.source, RegionNameSource::Static)
173+
{
174+
diag.help(&format!(
175+
"consider adding the following bound: `{fr_name}: {outlived_fr_name}`",
176+
));
178177
}
179178
}
180179

‎compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
337337
ty::Ref(_, inner_ty, mutbl) => {
338338
assert_eq!(*mutbl, rustc_hir::Mutability::Mut);
339339
(
340-
format!("a mutable reference to `{}`", inner_ty),
340+
format!("a mutable reference to `{inner_ty}`"),
341341
"mutable references are invariant over their type parameter"
342342
.to_string(),
343343
)
@@ -523,23 +523,19 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
523523
if let Some((Some(outlived_fr_name), outlived_fr_span)) = outlived_fr_name_and_span {
524524
diag.span_label(
525525
outlived_fr_span,
526-
format!(
527-
"`{}` declared here, outside of the {} body",
528-
outlived_fr_name, escapes_from
529-
),
526+
format!("`{outlived_fr_name}` declared here, outside of the {escapes_from} body",),
530527
);
531528
}
532529

533530
if let Some((Some(fr_name), fr_span)) = fr_name_and_span {
534531
diag.span_label(
535532
fr_span,
536533
format!(
537-
"`{}` is a reference that is only valid in the {} body",
538-
fr_name, escapes_from
534+
"`{fr_name}` is a reference that is only valid in the {escapes_from} body",
539535
),
540536
);
541537

542-
diag.span_label(*span, format!("`{}` escapes the {} body here", fr_name, escapes_from));
538+
diag.span_label(*span, format!("`{fr_name}` escapes the {escapes_from} body here"));
543539
}
544540

545541
// Only show an extra note if we can find an 'error region' for both of the region
@@ -611,9 +607,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
611607
diag.span_label(
612608
*span,
613609
format!(
614-
"{} was supposed to return data with lifetime `{}` but it is returning \
615-
data with lifetime `{}`",
616-
mir_def_name, outlived_fr_name, fr_name
610+
"{mir_def_name} was supposed to return data with lifetime `{outlived_fr_name}` but it is returning \
611+
data with lifetime `{fr_name}`",
617612
),
618613
);
619614
}
@@ -698,7 +693,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
698693
// If there is a static predicate, then the only sensible suggestion is to replace
699694
// fr with `'static`.
700695
if has_static_predicate {
701-
diag.help(&format!("consider replacing `{}` with `{}`", fr_name, static_str));
696+
diag.help(&format!("consider replacing `{fr_name}` with `{static_str}`"));
702697
} else {
703698
// Otherwise, we should suggest adding a constraint on the return type.
704699
let span = self.infcx.tcx.def_span(did);
@@ -714,14 +709,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
714709
} else {
715710
span
716711
};
717-
let suggestion = format!(" + {}", suggestable_fr_name);
712+
let suggestion = format!(" + {suggestable_fr_name}");
718713
let span = span.shrink_to_hi();
719714
diag.span_suggestion(
720715
span,
721716
&format!(
722717
"to allow this `impl Trait` to capture borrowed data with lifetime \
723-
`{}`, add `{}` as a bound",
724-
fr_name, suggestable_fr_name,
718+
`{fr_name}`, add `{suggestable_fr_name}` as a bound",
725719
),
726720
suggestion,
727721
Applicability::MachineApplicable,

‎compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,27 +102,24 @@ impl RegionName {
102102
match &self.source {
103103
RegionNameSource::NamedFreeRegion(span)
104104
| RegionNameSource::NamedEarlyBoundRegion(span) => {
105-
diag.span_label(*span, format!("lifetime `{}` defined here", self));
105+
diag.span_label(*span, format!("lifetime `{self}` defined here"));
106106
}
107107
RegionNameSource::SynthesizedFreeEnvRegion(span, note) => {
108-
diag.span_label(
109-
*span,
110-
format!("lifetime `{}` represents this closure's body", self),
111-
);
108+
diag.span_label(*span, format!("lifetime `{self}` represents this closure's body"));
112109
diag.note(note);
113110
}
114111
RegionNameSource::AnonRegionFromArgument(RegionNameHighlight::CannotMatchHirTy(
115112
span,
116113
type_name,
117114
)) => {
118-
diag.span_label(*span, format!("has type `{}`", type_name));
115+
diag.span_label(*span, format!("has type `{type_name}`"));
119116
}
120117
RegionNameSource::AnonRegionFromArgument(RegionNameHighlight::MatchedHirTy(span))
121118
| RegionNameSource::AnonRegionFromOutput(RegionNameHighlight::MatchedHirTy(span), _)
122119
| RegionNameSource::AnonRegionFromAsyncFn(span) => {
123120
diag.span_label(
124121
*span,
125-
format!("let's call the lifetime of this reference `{}`", self),
122+
format!("let's call the lifetime of this reference `{self}`"),
126123
);
127124
}
128125
RegionNameSource::AnonRegionFromArgument(
@@ -132,15 +129,15 @@ impl RegionName {
132129
RegionNameHighlight::MatchedAdtAndSegment(span),
133130
_,
134131
) => {
135-
diag.span_label(*span, format!("let's call this `{}`", self));
132+
diag.span_label(*span, format!("let's call this `{self}`"));
136133
}
137134
RegionNameSource::AnonRegionFromArgument(RegionNameHighlight::Occluded(
138135
span,
139136
type_name,
140137
)) => {
141138
diag.span_label(
142139
*span,
143-
format!("lifetime `{}` appears in the type {}", self, type_name),
140+
format!("lifetime `{self}` appears in the type {type_name}"),
144141
);
145142
}
146143
RegionNameSource::AnonRegionFromOutput(
@@ -150,25 +147,24 @@ impl RegionName {
150147
diag.span_label(
151148
*span,
152149
format!(
153-
"return type{} `{}` contains a lifetime `{}`",
154-
mir_description, type_name, self
150+
"return type{mir_description} `{type_name}` contains a lifetime `{self}`"
155151
),
156152
);
157153
}
158154
RegionNameSource::AnonRegionFromUpvar(span, upvar_name) => {
159155
diag.span_label(
160156
*span,
161-
format!("lifetime `{}` appears in the type of `{}`", self, upvar_name),
157+
format!("lifetime `{self}` appears in the type of `{upvar_name}`"),
162158
);
163159
}
164160
RegionNameSource::AnonRegionFromOutput(
165161
RegionNameHighlight::CannotMatchHirTy(span, type_name),
166162
mir_description,
167163
) => {
168-
diag.span_label(*span, format!("return type{} is {}", mir_description, type_name));
164+
diag.span_label(*span, format!("return type{mir_description} is {type_name}"));
169165
}
170166
RegionNameSource::AnonRegionFromYieldTy(span, type_name) => {
171-
diag.span_label(*span, format!("yield type is {}", type_name));
167+
diag.span_label(*span, format!("yield type is {type_name}"));
172168
}
173169
RegionNameSource::Static => {}
174170
}
@@ -442,7 +438,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
442438
"highlight_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}",
443439
type_name, needle_fr
444440
);
445-
if type_name.contains(&format!("'{}", counter)) {
441+
if type_name.contains(&format!("'{counter}")) {
446442
// Only add a label if we can confirm that a region was labelled.
447443
RegionNameHighlight::CannotMatchHirTy(span, type_name)
448444
} else {
@@ -809,7 +805,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
809805
// Note: generators from `async fn` yield `()`, so we don't have to
810806
// worry about them here.
811807
let yield_ty = self.regioncx.universal_regions().yield_ty?;
812-
debug!("give_name_if_anonymous_region_appears_in_yield_ty: yield_ty = {:?}", yield_ty,);
808+
debug!("give_name_if_anonymous_region_appears_in_yield_ty: yield_ty = {:?}", yield_ty);
813809

814810
let tcx = self.infcx.tcx;
815811

0 commit comments

Comments
 (0)
Please sign in to comment.