File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed
compiler/rustc_borrowck/src/diagnostics Expand file tree Collapse file tree 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>(
12631263 {
12641264 let span = span. with_lo ( span. lo ( ) + BytePos ( ws_pos as u32 ) ) . shrink_to_lo ( ) ;
12651265 ( true , span, " mut" . to_owned ( ) )
1266+ // if there is already a binding, we modify it to be `mut`
12661267 } else if binding_exists {
12671268 // shrink the span to just after the `&` in `&variable`
12681269 let span = span. with_lo ( span. lo ( ) + BytePos ( 1 ) ) . shrink_to_lo ( ) ;
12691270 ( true , span, "mut " . to_owned ( ) )
1271+ // otherwise, suggest that the user annotates the binding; we provide the
1272+ // type of the local.
12701273 } else {
12711274 let ty_mut = local_decl. ty . builtin_deref ( true ) . unwrap ( ) ;
12721275 assert_eq ! ( ty_mut. mutbl, hir:: Mutability :: Not ) ;
1276+
12731277 (
1274- binding_exists ,
1278+ false ,
12751279 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)
12811281 )
12821282 }
12831283}
You can’t perform that action at this time.
0 commit comments