summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_borrowck/src/diagnostics
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_borrowck/src/diagnostics')
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs64
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/mod.rs13
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs306
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/region_errors.rs4
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/region_name.rs18
5 files changed, 274 insertions, 131 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
index fe4a45b38..ee352e911 100644
--- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
@@ -1025,7 +1025,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
self.cannot_uniquely_borrow_by_two_closures(span, &desc_place, issued_span, None)
}
- (BorrowKind::Mut { .. }, BorrowKind::Shallow) => {
+ (BorrowKind::Mut { .. }, BorrowKind::Fake) => {
if let Some(immutable_section_description) =
self.classify_immutable_section(issued_borrow.assigned_place)
{
@@ -1117,11 +1117,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
)
}
- (BorrowKind::Shared, BorrowKind::Shared | BorrowKind::Shallow)
- | (
- BorrowKind::Shallow,
- BorrowKind::Mut { .. } | BorrowKind::Shared | BorrowKind::Shallow,
- ) => unreachable!(),
+ (BorrowKind::Shared, BorrowKind::Shared | BorrowKind::Fake)
+ | (BorrowKind::Fake, BorrowKind::Mut { .. } | BorrowKind::Shared | BorrowKind::Fake) => {
+ unreachable!()
+ }
};
if issued_spans == borrow_spans {
@@ -2130,21 +2129,27 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
/// misleading users in cases like `tests/ui/nll/borrowed-temporary-error.rs`.
/// We could expand the analysis to suggest hoising all of the relevant parts of
/// the users' code to make the code compile, but that could be too much.
- struct NestedStatementVisitor {
+ /// We found the `prop_expr` by the way to check whether the expression is a `FormatArguments`,
+ /// which is a special case since it's generated by the compiler.
+ struct NestedStatementVisitor<'tcx> {
span: Span,
current: usize,
found: usize,
+ prop_expr: Option<&'tcx hir::Expr<'tcx>>,
}
- impl<'tcx> Visitor<'tcx> for NestedStatementVisitor {
- fn visit_block(&mut self, block: &hir::Block<'tcx>) {
+ impl<'tcx> Visitor<'tcx> for NestedStatementVisitor<'tcx> {
+ fn visit_block(&mut self, block: &'tcx hir::Block<'tcx>) {
self.current += 1;
walk_block(self, block);
self.current -= 1;
}
- fn visit_expr(&mut self, expr: &hir::Expr<'tcx>) {
+ fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
if self.span == expr.span.source_callsite() {
self.found = self.current;
+ if self.prop_expr.is_none() {
+ self.prop_expr = Some(expr);
+ }
}
walk_expr(self, expr);
}
@@ -2162,22 +2167,40 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
span: proper_span,
current: 0,
found: 0,
+ prop_expr: None,
};
visitor.visit_stmt(stmt);
+
+ let typeck_results = self.infcx.tcx.typeck(self.mir_def_id());
+ let expr_ty: Option<Ty<'_>> = visitor.prop_expr.map(|expr| typeck_results.expr_ty(expr).peel_refs());
+
+ let is_format_arguments_item =
+ if let Some(expr_ty) = expr_ty
+ && let ty::Adt(adt, _) = expr_ty.kind() {
+ self.infcx.tcx.lang_items().get(LangItem::FormatArguments) == Some(adt.did())
+ } else {
+ false
+ };
+
if visitor.found == 0
&& stmt.span.contains(proper_span)
&& let Some(p) = sm.span_to_margin(stmt.span)
&& let Ok(s) = sm.span_to_snippet(proper_span)
{
- let addition = format!("let binding = {};\n{}", s, " ".repeat(p));
- err.multipart_suggestion_verbose(
- msg,
- vec![
- (stmt.span.shrink_to_lo(), addition),
- (proper_span, "binding".to_string()),
- ],
- Applicability::MaybeIncorrect,
- );
+ if !is_format_arguments_item {
+ let addition = format!("let binding = {};\n{}", s, " ".repeat(p));
+ err.multipart_suggestion_verbose(
+ msg,
+ vec![
+ (stmt.span.shrink_to_lo(), addition),
+ (proper_span, "binding".to_string()),
+ ],
+ Applicability::MaybeIncorrect,
+ );
+ } else {
+ err.note("the result of `format_args!` can only be assigned directly if no placeholders in it's arguments are used");
+ err.note("to learn more, visit <https://doc.rust-lang.org/std/macro.format_args.html>");
+ }
suggested = true;
break;
}
@@ -2620,7 +2643,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let loan_span = loan_spans.args_or_use();
let descr_place = self.describe_any_place(place.as_ref());
- if loan.kind == BorrowKind::Shallow {
+ if loan.kind == BorrowKind::Fake {
if let Some(section) = self.classify_immutable_section(loan.assigned_place) {
let mut err = self.cannot_mutate_in_immutable_section(
span,
@@ -2804,6 +2827,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}
ProjectionElem::ConstantIndex { .. }
| ProjectionElem::Subslice { .. }
+ | ProjectionElem::Subtype(_)
| ProjectionElem::Index(_) => kind,
},
place_ty.projection_ty(tcx, elem),
diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs
index 099e07e88..8d4028de9 100644
--- a/compiler/rustc_borrowck/src/diagnostics/mod.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs
@@ -13,7 +13,7 @@ use rustc_index::IndexSlice;
use rustc_infer::infer::LateBoundRegionConversionTime;
use rustc_middle::mir::tcx::PlaceTy;
use rustc_middle::mir::{
- AggregateKind, CallSource, Constant, FakeReadCause, Local, LocalInfo, LocalKind, Location,
+ AggregateKind, CallSource, ConstOperand, FakeReadCause, Local, LocalInfo, LocalKind, Location,
Operand, Place, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator,
TerminatorKind,
};
@@ -101,12 +101,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let terminator = self.body[location.block].terminator();
debug!("add_moved_or_invoked_closure_note: terminator={:?}", terminator);
if let TerminatorKind::Call {
- func: Operand::Constant(box Constant { literal, .. }),
+ func: Operand::Constant(box ConstOperand { const_, .. }),
args,
..
} = &terminator.kind
{
- if let ty::FnDef(id, _) = *literal.ty().kind() {
+ if let ty::FnDef(id, _) = *const_.ty().kind() {
debug!("add_moved_or_invoked_closure_note: id={:?}", id);
if Some(self.infcx.tcx.parent(id)) == self.infcx.tcx.lang_items().fn_once_trait() {
let closure = match args.first() {
@@ -242,6 +242,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
ProjectionElem::Downcast(..) if opt.including_downcast => return None,
ProjectionElem::Downcast(..) => (),
ProjectionElem::OpaqueCast(..) => (),
+ ProjectionElem::Subtype(..) => (),
ProjectionElem::Field(field, _ty) => {
// FIXME(project-rfc_2229#36): print capture precisely here.
if let Some(field) = self.is_upvar_field_projection(PlaceRef {
@@ -322,7 +323,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
PlaceRef { local, projection: proj_base }.ty(self.body, self.infcx.tcx)
}
ProjectionElem::Downcast(..) => place.ty(self.body, self.infcx.tcx),
- ProjectionElem::OpaqueCast(ty) => PlaceTy::from_ty(*ty),
+ ProjectionElem::Subtype(ty) | ProjectionElem::OpaqueCast(ty) => {
+ PlaceTy::from_ty(*ty)
+ }
ProjectionElem::Field(_, field_type) => PlaceTy::from_ty(*field_type),
},
};
@@ -628,7 +631,7 @@ impl UseSpans<'_> {
err.subdiagnostic(match kind {
Some(kd) => match kd {
rustc_middle::mir::BorrowKind::Shared
- | rustc_middle::mir::BorrowKind::Shallow => {
+ | rustc_middle::mir::BorrowKind::Fake => {
CaptureVarKind::Immut { kind_span: capture_kind_span }
}
diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
index d62541daf..8ca57383e 100644
--- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
@@ -1,9 +1,10 @@
+use hir::ExprKind;
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed};
use rustc_hir as hir;
use rustc_hir::intravisit::Visitor;
use rustc_hir::Node;
use rustc_middle::mir::{Mutability, Place, PlaceRef, ProjectionElem};
-use rustc_middle::ty::{self, Ty, TyCtxt};
+use rustc_middle::ty::{self, InstanceDef, Ty, TyCtxt};
use rustc_middle::{
hir::place::PlaceBase,
mir::{self, BindingForm, Local, LocalDecl, LocalInfo, LocalKind, Location},
@@ -158,6 +159,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
[
..,
ProjectionElem::Index(_)
+ | ProjectionElem::Subtype(_)
| ProjectionElem::ConstantIndex { .. }
| ProjectionElem::OpaqueCast { .. }
| ProjectionElem::Subslice { .. }
@@ -225,17 +227,17 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}
if suggest {
borrow_spans.var_subdiag(
- None,
- &mut err,
- Some(mir::BorrowKind::Mut { kind: mir::MutBorrowKind::Default }),
- |_kind, var_span| {
- let place = self.describe_any_place(access_place.as_ref());
- crate::session_diagnostics::CaptureVarCause::MutableBorrowUsePlaceClosure {
- place,
- var_span,
- }
- },
- );
+ None,
+ &mut err,
+ Some(mir::BorrowKind::Mut { kind: mir::MutBorrowKind::Default }),
+ |_kind, var_span| {
+ let place = self.describe_any_place(access_place.as_ref());
+ crate::session_diagnostics::CaptureVarCause::MutableBorrowUsePlaceClosure {
+ place,
+ var_span,
+ }
+ },
+ );
}
borrow_span
}
@@ -262,11 +264,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
} => {
err.span_label(span, format!("cannot {act}"));
- if let Some(span) = get_mut_span_in_struct_field(
- self.infcx.tcx,
- Place::ty_from(local, proj_base, self.body, self.infcx.tcx).ty,
- *field,
- ) {
+ let place = Place::ty_from(local, proj_base, self.body, self.infcx.tcx);
+ if let Some(span) = get_mut_span_in_struct_field(self.infcx.tcx, place.ty, *field) {
err.span_suggestion_verbose(
span,
"consider changing this to be mutable",
@@ -373,12 +372,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
err.span_label(span, format!("cannot {act}"));
}
if suggest {
- err.span_suggestion_verbose(
- local_decl.source_info.span.shrink_to_lo(),
- "consider changing this to be mutable",
- "mut ",
- Applicability::MachineApplicable,
- );
+ self.construct_mut_suggestion_for_local_binding_patterns(&mut err, local);
let tcx = self.infcx.tcx;
if let ty::Closure(id, _) = *the_place_err.ty(self.body, tcx).ty.kind() {
self.show_mutating_upvar(tcx, id.expect_local(), the_place_err, &mut err);
@@ -494,6 +488,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
),
);
+ self.suggest_using_iter_mut(&mut err);
self.suggest_make_local_mut(&mut err, local, name);
}
_ => {
@@ -713,6 +708,83 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
)
}
+ fn construct_mut_suggestion_for_local_binding_patterns(
+ &self,
+ err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
+ local: Local,
+ ) {
+ let local_decl = &self.body.local_decls[local];
+ debug!("local_decl: {:?}", local_decl);
+ let pat_span = match *local_decl.local_info() {
+ LocalInfo::User(BindingForm::Var(mir::VarBindingForm {
+ binding_mode: ty::BindingMode::BindByValue(Mutability::Not),
+ opt_ty_info: _,
+ opt_match_place: _,
+ pat_span,
+ })) => pat_span,
+ _ => local_decl.source_info.span,
+ };
+
+ struct BindingFinder {
+ span: Span,
+ hir_id: Option<hir::HirId>,
+ }
+
+ impl<'tcx> Visitor<'tcx> for BindingFinder {
+ fn visit_stmt(&mut self, s: &'tcx hir::Stmt<'tcx>) {
+ if let hir::StmtKind::Local(local) = s.kind {
+ if local.pat.span == self.span {
+ self.hir_id = Some(local.hir_id);
+ }
+ }
+ hir::intravisit::walk_stmt(self, s);
+ }
+ }
+
+ let hir_map = self.infcx.tcx.hir();
+ let def_id = self.body.source.def_id();
+ let hir_id = if let Some(local_def_id) = def_id.as_local()
+ && let Some(body_id) = hir_map.maybe_body_owned_by(local_def_id)
+ {
+ let body = hir_map.body(body_id);
+ let mut v = BindingFinder {
+ span: pat_span,
+ hir_id: None,
+ };
+ v.visit_body(body);
+ v.hir_id
+ } else {
+ None
+ };
+
+ // With ref-binding patterns, the mutability suggestion has to apply to
+ // the binding, not the reference (which would be a type error):
+ //
+ // `let &b = a;` -> `let &(mut b) = a;`
+ if let Some(hir_id) = hir_id
+ && let Some(hir::Node::Local(hir::Local {
+ pat: hir::Pat { kind: hir::PatKind::Ref(_, _), .. },
+ ..
+ })) = hir_map.find(hir_id)
+ && let Ok(name) = self.infcx.tcx.sess.source_map().span_to_snippet(local_decl.source_info.span)
+ {
+ err.span_suggestion(
+ pat_span,
+ "consider changing this to be mutable",
+ format!("&(mut {name})"),
+ Applicability::MachineApplicable,
+ );
+ return;
+ }
+
+ err.span_suggestion_verbose(
+ local_decl.source_info.span.shrink_to_lo(),
+ "consider changing this to be mutable",
+ "mut ",
+ Applicability::MachineApplicable,
+ );
+ }
+
// point to span of upvar making closure call require mutable borrow
fn show_mutating_upvar(
&self,
@@ -781,83 +853,88 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
// Attempt to search similar mutable associated items for suggestion.
// In the future, attempt in all path but initially for RHS of for_loop
- fn suggest_similar_mut_method_for_for_loop(&self, err: &mut Diagnostic) {
+ fn suggest_similar_mut_method_for_for_loop(&self, err: &mut Diagnostic, span: Span) {
use hir::{
- Expr,
- ExprKind::{Block, Call, DropTemps, Match, MethodCall},
+ BorrowKind, Expr,
+ ExprKind::{AddrOf, Block, Call, MethodCall},
};
let hir_map = self.infcx.tcx.hir();
- if let Some(body_id) = hir_map.maybe_body_owned_by(self.mir_def_id()) {
- if let Block(
- hir::Block {
- expr:
- Some(Expr {
- kind:
- DropTemps(Expr {
- kind:
- Match(
- Expr {
- kind:
- Call(
- _,
- [
- Expr {
- kind:
- MethodCall(path_segment, _, _, span),
- hir_id,
- ..
- },
- ..,
- ],
- ),
- ..
- },
- ..,
- ),
- ..
- }),
- ..
- }),
- ..
- },
- _,
- ) = hir_map.body(body_id).value.kind
- {
- let opt_suggestions = self
- .infcx
- .tcx
- .typeck(path_segment.hir_id.owner.def_id)
- .type_dependent_def_id(*hir_id)
- .and_then(|def_id| self.infcx.tcx.impl_of_method(def_id))
- .map(|def_id| self.infcx.tcx.associated_items(def_id))
- .map(|assoc_items| {
- assoc_items
- .in_definition_order()
- .map(|assoc_item_def| assoc_item_def.ident(self.infcx.tcx))
- .filter(|&ident| {
- let original_method_ident = path_segment.ident;
- original_method_ident != ident
- && ident
- .as_str()
- .starts_with(&original_method_ident.name.to_string())
- })
- .map(|ident| format!("{ident}()"))
- .peekable()
- });
+ struct Finder<'tcx> {
+ span: Span,
+ expr: Option<&'tcx Expr<'tcx>>,
+ }
- if let Some(mut suggestions) = opt_suggestions
- && suggestions.peek().is_some()
- {
- err.span_suggestions(
- *span,
- "use mutable method",
- suggestions,
- Applicability::MaybeIncorrect,
- );
+ impl<'tcx> Visitor<'tcx> for Finder<'tcx> {
+ fn visit_expr(&mut self, e: &'tcx hir::Expr<'tcx>) {
+ if e.span == self.span && self.expr.is_none() {
+ self.expr = Some(e);
}
+ hir::intravisit::walk_expr(self, e);
}
- };
+ }
+ if let Some(body_id) = hir_map.maybe_body_owned_by(self.mir_def_id())
+ && let Block(block, _) = hir_map.body(body_id).value.kind
+ {
+ // `span` corresponds to the expression being iterated, find the `for`-loop desugared
+ // expression with that span in order to identify potential fixes when encountering a
+ // read-only iterator that should be mutable.
+ let mut v = Finder {
+ span,
+ expr: None,
+ };
+ v.visit_block(block);
+ if let Some(expr) = v.expr && let Call(_, [expr]) = expr.kind {
+ match expr.kind {
+ MethodCall(path_segment, _, _, span) => {
+ // We have `for _ in iter.read_only_iter()`, try to
+ // suggest `for _ in iter.mutable_iter()` instead.
+ let opt_suggestions = self
+ .infcx
+ .tcx
+ .typeck(path_segment.hir_id.owner.def_id)
+ .type_dependent_def_id(expr.hir_id)
+ .and_then(|def_id| self.infcx.tcx.impl_of_method(def_id))
+ .map(|def_id| self.infcx.tcx.associated_items(def_id))
+ .map(|assoc_items| {
+ assoc_items
+ .in_definition_order()
+ .map(|assoc_item_def| assoc_item_def.ident(self.infcx.tcx))
+ .filter(|&ident| {
+ let original_method_ident = path_segment.ident;
+ original_method_ident != ident
+ && ident.as_str().starts_with(
+ &original_method_ident.name.to_string(),
+ )
+ })
+ .map(|ident| format!("{ident}()"))
+ .peekable()
+ });
+
+ if let Some(mut suggestions) = opt_suggestions
+ && suggestions.peek().is_some()
+ {
+ err.span_suggestions(
+ span,
+ "use mutable method",
+ suggestions,
+ Applicability::MaybeIncorrect,
+ );
+ }
+ }
+ AddrOf(BorrowKind::Ref, Mutability::Not, expr) => {
+ // We have `for _ in &i`, suggest `for _ in &mut i`.
+ err.span_suggestion_verbose(
+ expr.span.shrink_to_lo(),
+ "use a mutable iterator instead",
+ "mut ".to_string(),
+ Applicability::MachineApplicable,
+ );
+ }
+ _ => {}
+ }
+ }
+ }
}
/// Targeted error when encountering an `FnMut` closure where an `Fn` closure was expected.
@@ -951,6 +1028,44 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}
}
+ fn suggest_using_iter_mut(&self, err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>) {
+ let source = self.body.source;
+ let hir = self.infcx.tcx.hir();
+ if let InstanceDef::Item(def_id) = source.instance
+ && let Some(Node::Expr(hir::Expr { hir_id, kind, ..})) = hir.get_if_local(def_id)
+ && let ExprKind::Closure(closure) = kind && closure.movability == None
+ && let Some(Node::Expr(expr)) = hir.find_parent(*hir_id) {
+ let mut cur_expr = expr;
+ while let ExprKind::MethodCall(path_segment, recv, _, _) = cur_expr.kind {
+ if path_segment.ident.name == sym::iter {
+ // check `_ty` has `iter_mut` method
+ let res = self
+ .infcx
+ .tcx
+ .typeck(path_segment.hir_id.owner.def_id)
+ .type_dependent_def_id(cur_expr.hir_id)
+ .and_then(|def_id| self.infcx.tcx.impl_of_method(def_id))
+ .map(|def_id| self.infcx.tcx.associated_items(def_id))
+ .map(|assoc_items| {
+ assoc_items.filter_by_name_unhygienic(sym::iter_mut).peekable()
+ });
+
+ if let Some(mut res) = res && res.peek().is_some() {
+ err.span_suggestion_verbose(
+ path_segment.ident.span,
+ "you may want to use `iter_mut` here",
+ "iter_mut",
+ Applicability::MaybeIncorrect,
+ );
+ }
+ break;
+ } else {
+ cur_expr = recv;
+ }
+ }
+ }
+ }
+
fn suggest_make_local_mut(
&self,
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
@@ -1003,9 +1118,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
match opt_assignment_rhs_span.and_then(|s| s.desugaring_kind()) {
// on for loops, RHS points to the iterator part
Some(DesugaringKind::ForLoop) => {
- self.suggest_similar_mut_method_for_for_loop(err);
+ let span = opt_assignment_rhs_span.unwrap();
+ self.suggest_similar_mut_method_for_for_loop(err, span);
err.span_label(
- opt_assignment_rhs_span.unwrap(),
+ span,
format!("this iterator yields `{pointer_sigil}` {pointer_desc}s",),
);
None
diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs
index 2ea399789..27072a60f 100644
--- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs
@@ -245,7 +245,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let Trait(PolyTraitRef { trait_ref, span: trait_span, .. }, _) = bound else { return; };
diag.span_note(
*trait_span,
- format!("due to current limitations in the borrow checker, this implies a `'static` lifetime")
+ "due to current limitations in the borrow checker, this implies a `'static` lifetime"
);
let Some(generics_fn) = hir.get_generics(self.body.source.def_id().expect_local()) else { return; };
let Def(_, trait_res_defid) = trait_ref.path.res else { return; };
@@ -277,7 +277,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if suggestions.len() > 0 {
suggestions.dedup();
diag.multipart_suggestion_verbose(
- format!("consider restricting the type parameter to the `'static` lifetime"),
+ "consider restricting the type parameter to the `'static` lifetime",
suggestions,
Applicability::MaybeIncorrect,
);
diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs
index 337af89b2..55d581b3a 100644
--- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs
@@ -27,7 +27,7 @@ pub(crate) struct RegionName {
/// This helps to print the right kinds of diagnostics.
#[derive(Debug, Clone)]
pub(crate) enum RegionNameSource {
- /// A bound (not free) region that was substituted at the def site (not an HRTB).
+ /// A bound (not free) region that was instantiated at the def site (not an HRTB).
NamedEarlyBoundRegion(Span),
/// A free region that the user has a name (`'a`) for.
NamedFreeRegion(Span),
@@ -302,7 +302,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
if free_region.bound_region.is_named() {
// A named region that is actually named.
Some(RegionName { name, source: RegionNameSource::NamedFreeRegion(span) })
- } else if let hir::IsAsync::Async = tcx.asyncness(self.mir_hir_id().owner) {
+ } else if tcx.asyncness(self.mir_hir_id().owner).is_async() {
// If we spuriously thought that the region is named, we should let the
// system generate a true name for error messages. Currently this can
// happen if we have an elided name in an async fn for example: the
@@ -354,7 +354,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
})
}
- ty::BoundRegionKind::BrAnon(..) => None,
+ ty::BoundRegionKind::BrAnon => None,
},
ty::ReLateBound(..)
@@ -442,8 +442,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
span: Span,
counter: usize,
) -> RegionNameHighlight {
- let mut highlight = RegionHighlightMode::new(self.infcx.tcx);
- highlight.highlighting_region_vid(needle_fr, counter);
+ let mut highlight = RegionHighlightMode::default();
+ highlight.highlighting_region_vid(self.infcx.tcx, needle_fr, counter);
let type_name =
self.infcx.extract_inference_diagnostics_data(ty.into(), Some(highlight)).name;
@@ -516,7 +516,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
// be the same as those of the ADT.
// FIXME: We should be able to do something similar to
// match_adt_and_segment in this case.
- Res::Def(DefKind::TyAlias { .. }, _) => (),
+ Res::Def(DefKind::TyAlias, _) => (),
_ => {
if let Some(last_segment) = path.segments.last() {
if let Some(highlight) = self.match_adt_and_segment(
@@ -619,7 +619,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
// programs, so we need to use delay_span_bug here. See #82126.
self.infcx.tcx.sess.delay_span_bug(
hir_arg.span(),
- format!("unmatched subst and hir arg: found {kind:?} vs {hir_arg:?}"),
+ format!("unmatched arg and hir arg: found {kind:?} vs {hir_arg:?}"),
);
}
}
@@ -804,8 +804,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
return None;
}
- let mut highlight = RegionHighlightMode::new(tcx);
- highlight.highlighting_region_vid(fr, *self.next_region_name.try_borrow().unwrap());
+ let mut highlight = RegionHighlightMode::default();
+ highlight.highlighting_region_vid(tcx, fr, *self.next_region_name.try_borrow().unwrap());
let type_name =
self.infcx.extract_inference_diagnostics_data(yield_ty.into(), Some(highlight)).name;