1
Fork 0

use format-args-capture and remove unnecessary nested blocks

This commit is contained in:
Takayuki Maeda 2022-04-09 00:01:40 +09:00
parent dc1f8298ef
commit 470b4fca0e
5 changed files with 116 additions and 133 deletions

View file

@ -157,8 +157,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
// Error with the match place // Error with the match place
LookupResult::Parent(_) => { LookupResult::Parent(_) => {
for ge in &mut *grouped_errors { for ge in &mut *grouped_errors {
if let GroupedMoveError::MovesFromPlace { span, binds_to, .. } = ge { if let GroupedMoveError::MovesFromPlace { span, binds_to, .. } = ge
if match_span == *span { && match_span == *span
{
debug!("appending local({:?}) to list", bind_to); debug!("appending local({:?}) to list", bind_to);
if !binds_to.is_empty() { if !binds_to.is_empty() {
binds_to.push(bind_to); binds_to.push(bind_to);
@ -166,7 +167,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
return; return;
} }
} }
}
debug!("found a new move error location"); debug!("found a new move error location");
// Don't need to point to x in let x = ... . // Don't need to point to x in let x = ... .
@ -353,7 +353,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
None => bug!("closure kind not inferred by borrowck"), None => bug!("closure kind not inferred by borrowck"),
}; };
let capture_description = let capture_description =
format!("captured variable in an `{}` closure", closure_kind); format!("captured variable in an `{closure_kind}` closure");
let upvar = &self.upvars[upvar_field.unwrap().index()]; let upvar = &self.upvars[upvar_field.unwrap().index()];
let upvar_hir_id = upvar.place.get_root_variable(); let upvar_hir_id = upvar.place.get_root_variable();
@ -364,9 +364,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let place_description = let place_description =
if self.is_upvar_field_projection(move_place.as_ref()).is_some() { if self.is_upvar_field_projection(move_place.as_ref()).is_some() {
format!("{}, a {}", place_name, capture_description) format!("{place_name}, a {capture_description}")
} else { } else {
format!("{}, as `{}` is a {}", place_name, upvar_name, capture_description) format!("{place_name}, as `{upvar_name}` is a {capture_description}")
}; };
debug!( debug!(
@ -379,7 +379,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
diag.span_label(upvar_span, "captured outer variable"); diag.span_label(upvar_span, "captured outer variable");
diag.span_label( diag.span_label(
self.body.span, self.body.span,
format!("captured by this `{}` closure", closure_kind), format!("captured by this `{closure_kind}` closure"),
); );
diag diag
@ -390,7 +390,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
{ {
(Some(place_desc), Some(source_desc)) => self.cannot_move_out_of( (Some(place_desc), Some(source_desc)) => self.cannot_move_out_of(
span, span,
&format!("`{}` which is behind a {}", place_desc, source_desc), &format!("`{place_desc}` which is behind a {source_desc}"),
), ),
(_, _) => self.cannot_move_out_of( (_, _) => self.cannot_move_out_of(
span, span,
@ -435,7 +435,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
err.span_suggestion( err.span_suggestion(
span, span,
"consider borrowing here", "consider borrowing here",
format!("&{}", snippet), format!("&{snippet}"),
Applicability::Unspecified, Applicability::Unspecified,
); );
} }
@ -443,7 +443,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if binds_to.is_empty() { if binds_to.is_empty() {
let place_ty = move_from.ty(self.body, self.infcx.tcx).ty; let place_ty = move_from.ty(self.body, self.infcx.tcx).ty;
let place_desc = match self.describe_place(move_from.as_ref()) { let place_desc = match self.describe_place(move_from.as_ref()) {
Some(desc) => format!("`{}`", desc), Some(desc) => format!("`{desc}`"),
None => "value".to_string(), None => "value".to_string(),
}; };
@ -472,12 +472,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let span = use_spans.var_or_use(); let span = use_spans.var_or_use();
let place_ty = original_path.ty(self.body, self.infcx.tcx).ty; let place_ty = original_path.ty(self.body, self.infcx.tcx).ty;
let place_desc = match self.describe_place(original_path.as_ref()) { let place_desc = match self.describe_place(original_path.as_ref()) {
Some(desc) => format!("`{}`", desc), Some(desc) => format!("`{desc}`"),
None => "value".to_string(), None => "value".to_string(),
}; };
self.note_type_does_not_implement_copy(err, &place_desc, place_ty, Some(span), ""); self.note_type_does_not_implement_copy(err, &place_desc, place_ty, Some(span), "");
use_spans.args_span_label(err, format!("move out of {} occurs here", place_desc)); use_spans.args_span_label(err, format!("move out of {place_desc} occurs here"));
} }
} }
} }
@ -511,7 +511,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
for (span, to_remove, suggestion) in suggestions { for (span, to_remove, suggestion) in suggestions {
err.span_suggestion( err.span_suggestion(
span, span,
&format!("consider removing the `{}`", to_remove), &format!("consider removing the `{to_remove}`"),
suggestion, suggestion,
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );

View file

@ -55,7 +55,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
reason = ", as it is not declared as mutable".to_string(); reason = ", as it is not declared as mutable".to_string();
} else { } else {
let name = self.local_names[local].expect("immutable unnamed local"); let name = self.local_names[local].expect("immutable unnamed local");
reason = format!(", as `{}` is not declared as mutable", name); reason = format!(", as `{name}` is not declared as mutable");
} }
} }
@ -88,7 +88,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
reason = ", as it is not declared as mutable".to_string(); reason = ", as it is not declared as mutable".to_string();
} else { } else {
let name = self.upvars[upvar_index.index()].place.to_string(self.infcx.tcx); let name = self.upvars[upvar_index.index()].place.to_string(self.infcx.tcx);
reason = format!(", as `{}` is not declared as mutable", name); reason = format!(", as `{name}` is not declared as mutable");
} }
} }
} }
@ -103,14 +103,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if self.body.local_decls[local].is_ref_to_static() => if self.body.local_decls[local].is_ref_to_static() =>
{ {
if access_place.projection.len() == 1 { if access_place.projection.len() == 1 {
item_msg = format!("immutable static item {}", access_place_desc); item_msg = format!("immutable static item {access_place_desc}");
reason = String::new(); reason = String::new();
} else { } else {
item_msg = access_place_desc; item_msg = access_place_desc;
let local_info = &self.body.local_decls[local].local_info; let local_info = &self.body.local_decls[local].local_info;
if let Some(box LocalInfo::StaticRef { def_id, .. }) = *local_info { if let Some(box LocalInfo::StaticRef { def_id, .. }) = *local_info {
let static_name = &self.infcx.tcx.item_name(def_id); let static_name = &self.infcx.tcx.item_name(def_id);
reason = format!(", as `{}` is an immutable static item", static_name); reason = format!(", as `{static_name}` is an immutable static item");
} else { } else {
bug!("is_ref_to_static return true, but not ref to static?"); bug!("is_ref_to_static return true, but not ref to static?");
} }
@ -148,15 +148,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let pointer_type = source.describe_for_immutable_place(self.infcx.tcx); let pointer_type = source.describe_for_immutable_place(self.infcx.tcx);
opt_source = Some(source); opt_source = Some(source);
if let Some(desc) = self.describe_place(access_place.as_ref()) { if let Some(desc) = self.describe_place(access_place.as_ref()) {
item_msg = format!("`{}`", desc); item_msg = format!("`{desc}`");
reason = match error_access { reason = match error_access {
AccessKind::Mutate => format!(", which is behind {}", pointer_type), AccessKind::Mutate => format!(", which is behind {pointer_type}"),
AccessKind::MutableBorrow => { AccessKind::MutableBorrow => {
format!(", as it is behind {}", pointer_type) format!(", as it is behind {pointer_type}")
} }
} }
} else { } else {
item_msg = format!("data in {}", pointer_type); item_msg = format!("data in {pointer_type}");
reason = String::new(); reason = String::new();
} }
} }
@ -362,8 +362,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let upvar_hir_id = captured_place.get_root_variable(); let upvar_hir_id = captured_place.get_root_variable();
if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find(upvar_hir_id) { if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find(upvar_hir_id)
if let hir::PatKind::Binding( && let hir::PatKind::Binding(
hir::BindingAnnotation::Unannotated, hir::BindingAnnotation::Unannotated,
_, _,
upvar_ident, upvar_ident,
@ -377,16 +377,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );
} }
}
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
if let ty::Ref(_, ty, Mutability::Mut) = the_place_err.ty(self.body, tcx).ty.kind() if let ty::Ref(_, ty, Mutability::Mut) = the_place_err.ty(self.body, tcx).ty.kind()
&& let ty::Closure(id, _) = *ty.kind()
{ {
if let ty::Closure(id, _) = *ty.kind() {
self.show_mutating_upvar(tcx, id, the_place_err, &mut err); self.show_mutating_upvar(tcx, id, the_place_err, &mut err);
} }
} }
}
// complete hack to approximate old AST-borrowck // complete hack to approximate old AST-borrowck
// diagnostic: if the span starts with a mutable borrow of // diagnostic: if the span starts with a mutable borrow of
@ -544,8 +542,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
err.span_suggestion( err.span_suggestion(
err_help_span, err_help_span,
&format!( &format!(
"consider changing this to be a mutable {}", "consider changing this to be a mutable {pointer_desc}"
pointer_desc
), ),
suggested_code, suggested_code,
Applicability::MachineApplicable, Applicability::MachineApplicable,
@ -554,8 +551,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
err.span_suggestion( err.span_suggestion(
x, x,
&format!( &format!(
"consider changing that to be a mutable {}", "consider changing that to be a mutable {pointer_desc}"
pointer_desc
), ),
suggested_code, suggested_code,
Applicability::MachineApplicable, Applicability::MachineApplicable,
@ -606,15 +602,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
Some(BorrowedContentSource::OverloadedDeref(ty)) => { Some(BorrowedContentSource::OverloadedDeref(ty)) => {
err.help(&format!( err.help(&format!(
"trait `DerefMut` is required to modify through a dereference, \ "trait `DerefMut` is required to modify through a dereference, \
but it is not implemented for `{}`", but it is not implemented for `{ty}`",
ty,
)); ));
} }
Some(BorrowedContentSource::OverloadedIndex(ty)) => { Some(BorrowedContentSource::OverloadedIndex(ty)) => {
err.help(&format!( err.help(&format!(
"trait `IndexMut` is required to modify indexed content, \ "trait `IndexMut` is required to modify indexed content, \
but it is not implemented for `{}`", but it is not implemented for `{ty}`",
ty,
)); ));
} }
_ => (), _ => (),
@ -724,18 +718,18 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
ty::UpvarCapture::ByRef( ty::UpvarCapture::ByRef(
ty::BorrowKind::MutBorrow | ty::BorrowKind::UniqueImmBorrow, ty::BorrowKind::MutBorrow | ty::BorrowKind::UniqueImmBorrow,
) => { ) => {
capture_reason = format!("mutable borrow of `{}`", upvar); capture_reason = format!("mutable borrow of `{upvar}`");
} }
ty::UpvarCapture::ByValue => { ty::UpvarCapture::ByValue => {
capture_reason = format!("possible mutation of `{}`", upvar); capture_reason = format!("possible mutation of `{upvar}`");
} }
_ => bug!("upvar `{}` borrowed, but not mutably", upvar), _ => bug!("upvar `{upvar}` borrowed, but not mutably"),
} }
break; break;
} }
} }
if capture_reason.is_empty() { if capture_reason.is_empty() {
bug!("upvar `{}` borrowed, but cannot find reason", upvar); bug!("upvar `{upvar}` borrowed, but cannot find reason");
} }
capture_reason capture_reason
} else { } else {
@ -829,12 +823,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
.as_str() .as_str()
.starts_with(&original_method_ident.name.to_string()) .starts_with(&original_method_ident.name.to_string())
}) })
.map(|ident| format!("{}()", ident)) .map(|ident| format!("{ident}()"))
.peekable() .peekable()
}); });
if let Some(mut suggestions) = opt_suggestions { if let Some(mut suggestions) = opt_suggestions
if suggestions.peek().is_some() { && suggestions.peek().is_some()
{
err.span_suggestions( err.span_suggestions(
*span, *span,
"use mutable method", "use mutable method",
@ -843,13 +838,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
); );
} }
} }
}
}; };
} }
/// Targeted error when encountering an `FnMut` closure where an `Fn` closure was expected. /// Targeted error when encountering an `FnMut` closure where an `Fn` closure was expected.
fn expected_fn_found_fn_mut_call(&self, err: &mut Diagnostic, sp: Span, act: &str) { fn expected_fn_found_fn_mut_call(&self, err: &mut Diagnostic, sp: Span, act: &str) {
err.span_label(sp, format!("cannot {}", act)); err.span_label(sp, format!("cannot {act}"));
let hir = self.infcx.tcx.hir(); let hir = self.infcx.tcx.hir();
let closure_id = self.mir_hir_id(); let closure_id = self.mir_hir_id();
@ -1011,8 +1005,9 @@ fn suggest_ampmut<'tcx>(
opt_assignment_rhs_span: Option<Span>, opt_assignment_rhs_span: Option<Span>,
opt_ty_info: Option<Span>, opt_ty_info: Option<Span>,
) -> (Span, String) { ) -> (Span, String) {
if let Some(assignment_rhs_span) = opt_assignment_rhs_span { if let Some(assignment_rhs_span) = opt_assignment_rhs_span
if let Ok(src) = tcx.sess.source_map().span_to_snippet(assignment_rhs_span) { && let Ok(src) = tcx.sess.source_map().span_to_snippet(assignment_rhs_span)
{
let is_mutbl = |ty: &str| -> bool { let is_mutbl = |ty: &str| -> bool {
if let Some(rest) = ty.strip_prefix("mut") { if let Some(rest) = ty.strip_prefix("mut") {
match rest.chars().next() { match rest.chars().next() {
@ -1033,13 +1028,12 @@ fn suggest_ampmut<'tcx>(
let lt_name = &src[1..ws_pos]; let lt_name = &src[1..ws_pos];
let ty = src[ws_pos..].trim_start(); let ty = src[ws_pos..].trim_start();
if !is_mutbl(ty) { if !is_mutbl(ty) {
return (assignment_rhs_span, format!("&{} mut {}", lt_name, ty)); return (assignment_rhs_span, format!("&{lt_name} mut {ty}"));
} }
} else if let Some(stripped) = src.strip_prefix('&') { } else if let Some(stripped) = src.strip_prefix('&') {
let stripped = stripped.trim_start(); let stripped = stripped.trim_start();
if !is_mutbl(stripped) { if !is_mutbl(stripped) {
return (assignment_rhs_span, format!("&mut {}", stripped)); return (assignment_rhs_span, format!("&mut {stripped}"));
}
} }
} }
} }
@ -1054,13 +1048,13 @@ fn suggest_ampmut<'tcx>(
None => local_decl.source_info.span, None => local_decl.source_info.span,
}; };
if let Ok(src) = tcx.sess.source_map().span_to_snippet(highlight_span) { if let Ok(src) = tcx.sess.source_map().span_to_snippet(highlight_span)
if let (true, Some(ws_pos)) = (src.starts_with("&'"), src.find(char::is_whitespace)) { && let (true, Some(ws_pos)) = (src.starts_with("&'"), src.find(char::is_whitespace))
{
let lt_name = &src[1..ws_pos]; let lt_name = &src[1..ws_pos];
let ty = &src[ws_pos..]; let ty = &src[ws_pos..];
return (highlight_span, format!("&{} mut{}", lt_name, ty)); return (highlight_span, format!("&{} mut{}", lt_name, ty));
} }
}
let ty_mut = local_decl.ty.builtin_deref(true).unwrap(); let ty_mut = local_decl.ty.builtin_deref(true).unwrap();
assert_eq!(ty_mut.mutbl, hir::Mutability::Not); assert_eq!(ty_mut.mutbl, hir::Mutability::Not);

View file

@ -168,15 +168,14 @@ impl OutlivesSuggestionBuilder {
let fr_name = self.region_vid_to_name(mbcx, errci.fr); let fr_name = self.region_vid_to_name(mbcx, errci.fr);
let outlived_fr_name = self.region_vid_to_name(mbcx, errci.outlived_fr); let outlived_fr_name = self.region_vid_to_name(mbcx, errci.outlived_fr);
if let (Some(fr_name), Some(outlived_fr_name)) = (fr_name, outlived_fr_name) { if let (Some(fr_name), Some(outlived_fr_name)) = (fr_name, outlived_fr_name)
if !matches!(outlived_fr_name.source, RegionNameSource::Static) { && !matches!(outlived_fr_name.source, RegionNameSource::Static)
{
diag.help(&format!( diag.help(&format!(
"consider adding the following bound: `{}: {}`", "consider adding the following bound: `{fr_name}: {outlived_fr_name}`",
fr_name, outlived_fr_name
)); ));
} }
} }
}
/// If there is a suggestion to emit, add a diagnostic to the buffer. This is the final /// If there is a suggestion to emit, add a diagnostic to the buffer. This is the final
/// suggestion including all collected constraints. /// suggestion including all collected constraints.

View file

@ -337,7 +337,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
ty::Ref(_, inner_ty, mutbl) => { ty::Ref(_, inner_ty, mutbl) => {
assert_eq!(*mutbl, rustc_hir::Mutability::Mut); assert_eq!(*mutbl, rustc_hir::Mutability::Mut);
( (
format!("a mutable reference to `{}`", inner_ty), format!("a mutable reference to `{inner_ty}`"),
"mutable references are invariant over their type parameter" "mutable references are invariant over their type parameter"
.to_string(), .to_string(),
) )
@ -523,10 +523,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if let Some((Some(outlived_fr_name), outlived_fr_span)) = outlived_fr_name_and_span { if let Some((Some(outlived_fr_name), outlived_fr_span)) = outlived_fr_name_and_span {
diag.span_label( diag.span_label(
outlived_fr_span, outlived_fr_span,
format!( format!("`{outlived_fr_name}` declared here, outside of the {escapes_from} body",),
"`{}` declared here, outside of the {} body",
outlived_fr_name, escapes_from
),
); );
} }
@ -534,12 +531,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
diag.span_label( diag.span_label(
fr_span, fr_span,
format!( format!(
"`{}` is a reference that is only valid in the {} body", "`{fr_name}` is a reference that is only valid in the {escapes_from} body",
fr_name, escapes_from
), ),
); );
diag.span_label(*span, format!("`{}` escapes the {} body here", fr_name, escapes_from)); diag.span_label(*span, format!("`{fr_name}` escapes the {escapes_from} body here"));
} }
// Only show an extra note if we can find an 'error region' for both of the region // 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> {
diag.span_label( diag.span_label(
*span, *span,
format!( format!(
"{} was supposed to return data with lifetime `{}` but it is returning \ "{mir_def_name} was supposed to return data with lifetime `{outlived_fr_name}` but it is returning \
data with lifetime `{}`", data with lifetime `{fr_name}`",
mir_def_name, outlived_fr_name, fr_name
), ),
); );
} }
@ -698,7 +693,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
// If there is a static predicate, then the only sensible suggestion is to replace // If there is a static predicate, then the only sensible suggestion is to replace
// fr with `'static`. // fr with `'static`.
if has_static_predicate { if has_static_predicate {
diag.help(&format!("consider replacing `{}` with `{}`", fr_name, static_str)); diag.help(&format!("consider replacing `{fr_name}` with `{static_str}`"));
} else { } else {
// Otherwise, we should suggest adding a constraint on the return type. // Otherwise, we should suggest adding a constraint on the return type.
let span = self.infcx.tcx.def_span(did); let span = self.infcx.tcx.def_span(did);
@ -714,14 +709,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
} else { } else {
span span
}; };
let suggestion = format!(" + {}", suggestable_fr_name); let suggestion = format!(" + {suggestable_fr_name}");
let span = span.shrink_to_hi(); let span = span.shrink_to_hi();
diag.span_suggestion( diag.span_suggestion(
span, span,
&format!( &format!(
"to allow this `impl Trait` to capture borrowed data with lifetime \ "to allow this `impl Trait` to capture borrowed data with lifetime \
`{}`, add `{}` as a bound", `{fr_name}`, add `{suggestable_fr_name}` as a bound",
fr_name, suggestable_fr_name,
), ),
suggestion, suggestion,
Applicability::MachineApplicable, Applicability::MachineApplicable,

View file

@ -102,27 +102,24 @@ impl RegionName {
match &self.source { match &self.source {
RegionNameSource::NamedFreeRegion(span) RegionNameSource::NamedFreeRegion(span)
| RegionNameSource::NamedEarlyBoundRegion(span) => { | RegionNameSource::NamedEarlyBoundRegion(span) => {
diag.span_label(*span, format!("lifetime `{}` defined here", self)); diag.span_label(*span, format!("lifetime `{self}` defined here"));
} }
RegionNameSource::SynthesizedFreeEnvRegion(span, note) => { RegionNameSource::SynthesizedFreeEnvRegion(span, note) => {
diag.span_label( diag.span_label(*span, format!("lifetime `{self}` represents this closure's body"));
*span,
format!("lifetime `{}` represents this closure's body", self),
);
diag.note(note); diag.note(note);
} }
RegionNameSource::AnonRegionFromArgument(RegionNameHighlight::CannotMatchHirTy( RegionNameSource::AnonRegionFromArgument(RegionNameHighlight::CannotMatchHirTy(
span, span,
type_name, type_name,
)) => { )) => {
diag.span_label(*span, format!("has type `{}`", type_name)); diag.span_label(*span, format!("has type `{type_name}`"));
} }
RegionNameSource::AnonRegionFromArgument(RegionNameHighlight::MatchedHirTy(span)) RegionNameSource::AnonRegionFromArgument(RegionNameHighlight::MatchedHirTy(span))
| RegionNameSource::AnonRegionFromOutput(RegionNameHighlight::MatchedHirTy(span), _) | RegionNameSource::AnonRegionFromOutput(RegionNameHighlight::MatchedHirTy(span), _)
| RegionNameSource::AnonRegionFromAsyncFn(span) => { | RegionNameSource::AnonRegionFromAsyncFn(span) => {
diag.span_label( diag.span_label(
*span, *span,
format!("let's call the lifetime of this reference `{}`", self), format!("let's call the lifetime of this reference `{self}`"),
); );
} }
RegionNameSource::AnonRegionFromArgument( RegionNameSource::AnonRegionFromArgument(
@ -132,7 +129,7 @@ impl RegionName {
RegionNameHighlight::MatchedAdtAndSegment(span), RegionNameHighlight::MatchedAdtAndSegment(span),
_, _,
) => { ) => {
diag.span_label(*span, format!("let's call this `{}`", self)); diag.span_label(*span, format!("let's call this `{self}`"));
} }
RegionNameSource::AnonRegionFromArgument(RegionNameHighlight::Occluded( RegionNameSource::AnonRegionFromArgument(RegionNameHighlight::Occluded(
span, span,
@ -140,7 +137,7 @@ impl RegionName {
)) => { )) => {
diag.span_label( diag.span_label(
*span, *span,
format!("lifetime `{}` appears in the type {}", self, type_name), format!("lifetime `{self}` appears in the type {type_name}"),
); );
} }
RegionNameSource::AnonRegionFromOutput( RegionNameSource::AnonRegionFromOutput(
@ -150,25 +147,24 @@ impl RegionName {
diag.span_label( diag.span_label(
*span, *span,
format!( format!(
"return type{} `{}` contains a lifetime `{}`", "return type{mir_description} `{type_name}` contains a lifetime `{self}`"
mir_description, type_name, self
), ),
); );
} }
RegionNameSource::AnonRegionFromUpvar(span, upvar_name) => { RegionNameSource::AnonRegionFromUpvar(span, upvar_name) => {
diag.span_label( diag.span_label(
*span, *span,
format!("lifetime `{}` appears in the type of `{}`", self, upvar_name), format!("lifetime `{self}` appears in the type of `{upvar_name}`"),
); );
} }
RegionNameSource::AnonRegionFromOutput( RegionNameSource::AnonRegionFromOutput(
RegionNameHighlight::CannotMatchHirTy(span, type_name), RegionNameHighlight::CannotMatchHirTy(span, type_name),
mir_description, mir_description,
) => { ) => {
diag.span_label(*span, format!("return type{} is {}", mir_description, type_name)); diag.span_label(*span, format!("return type{mir_description} is {type_name}"));
} }
RegionNameSource::AnonRegionFromYieldTy(span, type_name) => { RegionNameSource::AnonRegionFromYieldTy(span, type_name) => {
diag.span_label(*span, format!("yield type is {}", type_name)); diag.span_label(*span, format!("yield type is {type_name}"));
} }
RegionNameSource::Static => {} RegionNameSource::Static => {}
} }
@ -442,7 +438,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
"highlight_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}", "highlight_if_we_cannot_match_hir_ty: type_name={:?} needle_fr={:?}",
type_name, needle_fr type_name, needle_fr
); );
if type_name.contains(&format!("'{}", counter)) { if type_name.contains(&format!("'{counter}")) {
// Only add a label if we can confirm that a region was labelled. // Only add a label if we can confirm that a region was labelled.
RegionNameHighlight::CannotMatchHirTy(span, type_name) RegionNameHighlight::CannotMatchHirTy(span, type_name)
} else { } else {
@ -809,7 +805,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
// Note: generators from `async fn` yield `()`, so we don't have to // Note: generators from `async fn` yield `()`, so we don't have to
// worry about them here. // worry about them here.
let yield_ty = self.regioncx.universal_regions().yield_ty?; let yield_ty = self.regioncx.universal_regions().yield_ty?;
debug!("give_name_if_anonymous_region_appears_in_yield_ty: yield_ty = {:?}", yield_ty,); debug!("give_name_if_anonymous_region_appears_in_yield_ty: yield_ty = {:?}", yield_ty);
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;