@@ -1150,7 +1150,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
1150
1150
None
1151
1151
}
1152
1152
None => {
1153
- let ( has_sugg , decl_span , sugg ) = if name != kw:: SelfLower {
1153
+ if name != kw:: SelfLower {
1154
1154
suggest_ampmut (
1155
1155
self . infcx . tcx ,
1156
1156
local_decl. ty ,
@@ -1165,7 +1165,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
1165
1165
..
1166
1166
} ) ) => {
1167
1167
let sugg = suggest_ampmut_self ( self . infcx . tcx , decl_span) ;
1168
- ( true , decl_span, sugg)
1168
+ Some ( ( true , decl_span, sugg, None ) )
1169
1169
}
1170
1170
// explicit self (eg `self: &'a Self`)
1171
1171
_ => suggest_ampmut (
@@ -1176,8 +1176,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
1176
1176
opt_ty_info,
1177
1177
) ,
1178
1178
}
1179
- } ;
1180
- Some ( ( has_sugg, decl_span, sugg, None ) )
1179
+ }
1181
1180
}
1182
1181
}
1183
1182
}
@@ -1443,7 +1442,7 @@ fn suggest_ampmut<'tcx>(
1443
1442
decl_span : Span ,
1444
1443
opt_assignment_rhs_span : Option < Span > ,
1445
1444
opt_ty_info : Option < Span > ,
1446
- ) -> ( bool , Span , String ) {
1445
+ ) -> Option < ( bool , Span , String , Option < ( Span , String ) > ) > {
1447
1446
// if there is a RHS and it starts with a `&` from it, then check if it is
1448
1447
// mutable, and if not, put suggest putting `mut ` to make it mutable.
1449
1448
// we don't have to worry about lifetime annotations here because they are
@@ -1479,7 +1478,7 @@ fn suggest_ampmut<'tcx>(
1479
1478
1480
1479
// FIXME(Ezrashaw): returning is bad because we still might want to
1481
1480
// update the annotated type, see #106857.
1482
- return ( true , span, "mut " . to_owned ( ) ) ;
1481
+ return Some ( ( true , span, "mut " . to_owned ( ) , None ) ) ;
1483
1482
}
1484
1483
}
1485
1484
@@ -1504,18 +1503,18 @@ fn suggest_ampmut<'tcx>(
1504
1503
&& let Some ( ws_pos) = src. find ( char:: is_whitespace)
1505
1504
{
1506
1505
let span = span. with_lo ( span. lo ( ) + BytePos ( ws_pos as u32 ) ) . shrink_to_lo ( ) ;
1507
- ( true , span, " mut" . to_owned ( ) )
1506
+ Some ( ( true , span, " mut" . to_owned ( ) , None ) )
1508
1507
// if there is already a binding, we modify it to be `mut`
1509
1508
} else if binding_exists {
1510
1509
// shrink the span to just after the `&` in `&variable`
1511
1510
let span = span. with_lo ( span. lo ( ) + BytePos ( 1 ) ) . shrink_to_lo ( ) ;
1512
- ( true , span, "mut " . to_owned ( ) )
1511
+ Some ( ( true , span, "mut " . to_owned ( ) , None ) )
1513
1512
} else {
1514
1513
// otherwise, suggest that the user annotates the binding; we provide the
1515
1514
// type of the local.
1516
1515
let ty = decl_ty. builtin_deref ( true ) . unwrap ( ) ;
1517
1516
1518
- ( false , span, format ! ( "{}mut {}" , if decl_ty. is_ref( ) { "&" } else { "*" } , ty) )
1517
+ Some ( ( false , span, format ! ( "{}mut {}" , if decl_ty. is_ref( ) { "&" } else { "*" } , ty) , None ) )
1519
1518
}
1520
1519
}
1521
1520
0 commit comments