File tree 1 file changed +6
-6
lines changed
compiler/rustc_borrowck/src/diagnostics
1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -1263,21 +1263,21 @@ fn suggest_ampmut<'tcx>(
1263
1263
{
1264
1264
let span = span. with_lo ( span. lo ( ) + BytePos ( ws_pos as u32 ) ) . shrink_to_lo ( ) ;
1265
1265
( true , span, " mut" . to_owned ( ) )
1266
+ // if there is already a binding, we modify it to be `mut`
1266
1267
} else if binding_exists {
1267
1268
// shrink the span to just after the `&` in `&variable`
1268
1269
let span = span. with_lo ( span. lo ( ) + BytePos ( 1 ) ) . shrink_to_lo ( ) ;
1269
1270
( true , span, "mut " . to_owned ( ) )
1271
+ // otherwise, suggest that the user annotates the binding; we provide the
1272
+ // type of the local.
1270
1273
} else {
1271
1274
let ty_mut = local_decl. ty . builtin_deref ( true ) . unwrap ( ) ;
1272
1275
assert_eq ! ( ty_mut. mutbl, hir:: Mutability :: Not ) ;
1276
+
1273
1277
(
1274
- binding_exists ,
1278
+ false ,
1275
1279
span,
1276
- if local_decl. ty . is_ref ( ) {
1277
- format ! ( "&mut {}" , ty_mut. ty)
1278
- } else {
1279
- format ! ( "*mut {}" , ty_mut. ty)
1280
- } ,
1280
+ format ! ( "{}mut {}" , if local_decl. ty. is_ref( ) { "&" } else { "*" } , ty_mut. ty)
1281
1281
)
1282
1282
}
1283
1283
}
You can’t perform that action at this time.
0 commit comments