@@ -413,7 +413,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
413413 }
414414 }
415415
416- // Also suggest adding mut for upvars
416+ // Also suggest adding mut for upvars.
417417 PlaceRef {
418418 local,
419419 projection : [ proj_base @ .., ProjectionElem :: Field ( upvar_index, _) ] ,
@@ -467,9 +467,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
467467 }
468468 }
469469
470- // complete hack to approximate old AST-borrowck
471- // diagnostic: if the span starts with a mutable borrow of
472- // a local variable, then just suggest the user remove it.
470+ // Complete hack to approximate old AST-borrowck diagnostic: if the span starts
471+ // with a mutable borrow of a local variable, then just suggest the user remove it.
473472 PlaceRef { local : _, projection : [ ] }
474473 if self
475474 . infcx
@@ -798,7 +797,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
798797 ) ;
799798 }
800799
801- // point to span of upvar making closure call require mutable borrow
800+ // Point to span of upvar making closure call that requires a mutable borrow
802801 fn show_mutating_upvar (
803802 & self ,
804803 tcx : TyCtxt < ' _ > ,
@@ -854,7 +853,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
854853 } else {
855854 bug ! ( "not an upvar" )
856855 } ;
857- // sometimes we deliberately don't store the name of a place when coming from a macro in
856+ // Sometimes we deliberately don't store the name of a place when coming from a macro in
858857 // another crate. We generally want to limit those diagnostics a little, to hide
859858 // implementation details (such as those from pin!() or format!()). In that case show a
860859 // slightly different error message, or none at all if something else happened. In other
@@ -965,8 +964,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
965964 let def_id = tcx. hir_enclosing_body_owner ( fn_call_id) ;
966965 let mut look_at_return = true ;
967966
968- // If the HIR node is a function or method call gets the def ID
969- // of the called function or method and the span and args of the call expr
967+ // If the HIR node is a function or method call, get the DefId
968+ // of the callee function or method, the span, and args of the call expr
970969 let get_call_details = || {
971970 let hir:: Node :: Expr ( hir:: Expr { hir_id, kind, .. } ) = node else {
972971 return None ;
@@ -1080,7 +1079,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
10801079 let mut cur_expr = expr;
10811080 while let ExprKind :: MethodCall ( path_segment, recv, _, _) = cur_expr. kind {
10821081 if path_segment. ident . name == sym:: iter {
1083- // check `_ty` has `iter_mut` method
1082+ // Check that the type has an `iter_mut` method.
10841083 let res = self
10851084 . infcx
10861085 . tcx
@@ -1119,7 +1118,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11191118 let ( is_trait_sig, is_local, local_trait) = self . is_error_in_trait ( local) ;
11201119
11211120 if is_trait_sig && !is_local {
1122- // Do not suggest to change the signature when the trait comes from another crate.
1121+ // Do not suggest changing the signature when the trait comes from another crate.
11231122 err. span_label (
11241123 local_decl. source_info . span ,
11251124 format ! ( "this is an immutable {pointer_desc}" ) ,
@@ -1140,7 +1139,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11401139 opt_ty_info,
11411140 ..
11421141 } ) ) => {
1143- // check if the RHS is from desugaring
1142+ // Check if the RHS is from desugaring.
11441143 let first_assignment = find_assignments ( & self . body , local) . first ( ) . copied ( ) ;
11451144 let first_assignment_stmt = first_assignment
11461145 . and_then ( |loc| self . body [ loc. block ] . statements . get ( loc. statement_index ) ) ;
@@ -1160,7 +1159,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11601159 // it with does not, so use the local_span for our checks later.
11611160 source_span = Some ( local_span) ;
11621161 if let Some ( DesugaringKind :: ForLoop ) = local_span. desugaring_kind ( ) {
1163- // on for loops, RHS points to the iterator part
1162+ // On for loops, RHS points to the iterator part.
11641163 self . suggest_similar_mut_method_for_for_loop ( err, local_span) ;
11651164 err. span_label (
11661165 local_span,
@@ -1170,14 +1169,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11701169 }
11711170 }
11721171
1173- // don 't create labels for compiler-generated spans or spans not from users' code
1172+ // Don 't create labels for compiler-generated spans or spans not from users' code.
11741173 if source_span. is_some_and ( |s| {
11751174 s. desugaring_kind ( ) . is_some ( ) || self . infcx . tcx . sess . source_map ( ) . is_imported ( s)
11761175 } ) {
11771176 return ;
11781177 }
11791178
1180- // could be because we're in an `async fn`
1179+ // This could be because we're in an `async fn`.
11811180 if name == kw:: SelfLower && opt_ty_info. is_none ( ) {
11821181 let ( span, suggestion) = suggest_ampmut_self ( self . infcx . tcx , decl_span) ;
11831182 ( AmpMutSugg :: Type { span, suggestion, additional : None } , None )
@@ -1249,16 +1248,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
12491248 AmpMutSugg :: ChangeBinding => ( vec ! [ ] , true ) ,
12501249 } ;
12511250
1252- // find a binding's type to make mutable.
1251+ // Find a binding's type to make mutable.
12531252 let ( binding_exists, span) = match local_var_ty_info {
1254- // if this is a variable binding with an explicit type,
1253+ // If this is a variable binding with an explicit type,
12551254 // then we will suggest changing it to be mutable.
1256- // this is `Applicability::MachineApplicable`.
1255+ // This is `Applicability::MachineApplicable`.
12571256 Some ( ty_span) => ( true , ty_span) ,
12581257
1259- // otherwise , we'll suggest *adding* an annotated type, we'll suggest
1258+ // Otherwise , we'll suggest *adding* an annotated type, we'll suggest
12601259 // the RHS's type for that.
1261- // this is `Applicability::HasPlaceholders`.
1260+ // This is `Applicability::HasPlaceholders`.
12621261 None => ( false , decl_span) ,
12631262 } ;
12641263
@@ -1267,31 +1266,31 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
12671266 return ;
12681267 }
12691268
1270- // if the binding already exists and is a reference with an explicit
1271- // lifetime, then we can suggest adding ` mut`. this is special-cased from
1269+ // If the binding already exists and is a reference with an explicit
1270+ // lifetime, then we can suggest adding ` mut`. This is special-cased from
12721271 // the path without an explicit lifetime.
12731272 let ( sugg_span, sugg_str, suggest_now) = if let Ok ( src) = self . infcx . tcx . sess . source_map ( ) . span_to_snippet ( span)
12741273 && src. starts_with ( "&'" )
1275- // note that `&' a T` is invalid so this is correct.
1274+ // Note that `&' a T` is invalid so this is correct.
12761275 && let Some ( ws_pos) = src. find ( char:: is_whitespace)
12771276 {
12781277 let span = span. with_lo ( span. lo ( ) + BytePos ( ws_pos as u32 ) ) . shrink_to_lo ( ) ;
12791278 ( span, " mut" . to_owned ( ) , true )
1280- // if there is already a binding, we modify it to be `mut`
1279+ // If there is already a binding, we modify it to be `mut`.
12811280 } else if binding_exists {
1282- // shrink the span to just after the `&` in `&variable`
1281+ // Shrink the span to just after the `&` in `&variable`.
12831282 let span = span. with_lo ( span. lo ( ) + BytePos ( 1 ) ) . shrink_to_lo ( ) ;
12841283 ( span, "mut " . to_owned ( ) , true )
12851284 } else {
1286- // otherwise , suggest that the user annotates the binding; we provide the
1285+ // Otherwise , suggest that the user annotates the binding; We provide the
12871286 // type of the local.
12881287 let ty = local_decl. ty . builtin_deref ( true ) . unwrap ( ) ;
12891288
12901289 ( span, format ! ( "{}mut {}" , if local_decl. ty. is_ref( ) { "&" } else { "*" } , ty) , false )
12911290 } ;
12921291
12931292 if suggest_now {
1294- // suggest changing `&x` to `&mut x` and changing `&T` to `&mut T` at the same time
1293+ // Suggest changing `&x` to `&mut x` and changing `&T` to `&mut T` at the same time.
12951294 let has_change = !sugg. is_empty ( ) ;
12961295 sugg. push ( ( sugg_span, sugg_str) ) ;
12971296 suggest (
@@ -1535,9 +1534,9 @@ fn suggest_ampmut<'tcx>(
15351534 opt_assignment_rhs_stmt : Option < & Statement < ' tcx > > ,
15361535) -> Option < AmpMutSugg > {
15371536 let tcx = infcx. tcx ;
1538- // if there is a RHS and it starts with a `&` from it, then check if it is
1537+ // If there is a RHS and it starts with a `&` from it, then check if it is
15391538 // mutable, and if not, put suggest putting `mut ` to make it mutable.
1540- // we don't have to worry about lifetime annotations here because they are
1539+ // We don't have to worry about lifetime annotations here because they are
15411540 // not valid when taking a reference. For example, the following is not valid Rust:
15421541 //
15431542 // let x: &i32 = &'a 5;
@@ -1550,15 +1549,15 @@ fn suggest_ampmut<'tcx>(
15501549 {
15511550 let mut rvalue = rvalue;
15521551
1553- // take some special care when handling `let _x = &*_y`:
1554- // we want to know if this is part of an overloaded index, so `let x = &a[0]`,
1555- // or whether this is a usertype ascription (`let _x: &T = y`)
1552+ // Take some special care when handling `let _x = &*_y`:
1553+ // We want to know if this is part of an overloaded index, so `let x = &a[0]`,
1554+ // or whether this is a usertype ascription (`let _x: &T = y`).
15561555 if let Rvalue :: Ref ( _, BorrowKind :: Shared , place) = rvalue
15571556 && place. projection . len ( ) == 1
15581557 && place. projection [ 0 ] == ProjectionElem :: Deref
15591558 && let Some ( assign) = find_assignments ( & body, place. local ) . first ( )
15601559 {
1561- // if this is a usertype ascription (`let _x: &T = _y`) then pierce through it as either we want
1560+ // If this is a usertype ascription (`let _x: &T = _y`) then pierce through it as either we want
15621561 // to suggest `&mut` on the expression (handled here) or we return `None` and let the caller
15631562 // suggest `&mut` on the type if the expression seems fine (e.g. `let _x: &T = &mut _y`).
15641563 if let Some ( user_ty_projs) = body. local_decls [ lhs. local ] . user_ty . as_ref ( )
@@ -1585,12 +1584,12 @@ fn suggest_ampmut<'tcx>(
15851584 tcx. require_lang_item ( hir:: LangItem :: IndexMut , rhs_span) ,
15861585 method_args,
15871586 ) ;
1588- // the type only implements `Index` but not `IndexMut`, we must not suggest `&mut`.
1587+ // The type only implements `Index` but not `IndexMut`, we must not suggest `&mut`.
15891588 if !infcx
15901589 . type_implements_trait ( trait_ref. def_id , trait_ref. args , infcx. param_env )
15911590 . must_apply_considering_regions ( )
15921591 {
1593- // suggest `get_mut` if type is a `BTreeMap` or `HashMap`.
1592+ // Suggest `get_mut` if type is a `BTreeMap` or `HashMap`.
15941593 if let ty:: Adt ( def, _) = trait_ref. self_ty ( ) . kind ( )
15951594 && [ sym:: BTreeMap , sym:: HashMap ]
15961595 . into_iter ( )
@@ -1610,7 +1609,7 @@ fn suggest_ampmut<'tcx>(
16101609
16111610 let sugg = match rvalue {
16121611 Rvalue :: Ref ( _, BorrowKind :: Shared , _) if let Some ( ref_idx) = rhs_str. find ( '&' ) => {
1613- // shrink the span to just after the `&` in `&variable`
1612+ // Shrink the span to just after the `&` in `&variable`.
16141613 Some ( (
16151614 rhs_span. with_lo ( rhs_span. lo ( ) + BytePos ( ref_idx as u32 + 1 ) ) . shrink_to_lo ( ) ,
16161615 "mut " . to_owned ( ) ,
0 commit comments