about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2024-07-03 23:26:10 +0000
committerEsteban Küber <esteban@kuber.com.ar>2024-07-04 05:36:34 +0000
commitff92ab09033d2b08689e8a1fafe607d51b01d8d2 (patch)
tree27faba8eb3c3a3a4374a21955832b06d2a507f33
parent2699d8108cee47a86de22d8ac29344bcadfdbd45 (diff)
downloadrust-ff92ab09033d2b08689e8a1fafe607d51b01d8d2.tar.gz
rust-ff92ab09033d2b08689e8a1fafe607d51b01d8d2.zip
More accurate mutability suggestion
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs25
-rw-r--r--tests/ui/borrowck/borrow-raw-address-of-mutability.stderr8
-rw-r--r--tests/ui/borrowck/borrowck-closures-unique.stderr7
-rw-r--r--tests/ui/borrowck/issue-111554.stderr7
-rw-r--r--tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.stderr48
-rw-r--r--tests/ui/borrowck/mutability-errors.stderr64
-rw-r--r--tests/ui/cannot-mutate-captured-non-mut-var.stderr14
-rw-r--r--tests/ui/closures/2229_closure_analysis/array_subslice.stderr8
-rw-r--r--tests/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm.stderr16
-rw-r--r--tests/ui/closures/closure-immutable-outer-variable.stderr7
-rw-r--r--tests/ui/fn/suggest-return-closure.stderr8
-rw-r--r--tests/ui/nll/closure-captures.stderr48
-rw-r--r--tests/ui/nll/coroutine-upvar-mutability.stderr8
-rw-r--r--tests/ui/nll/issue-46023.stderr8
-rw-r--r--tests/ui/pattern/patkind-ref-binding-issue-114896.stderr7
-rw-r--r--tests/ui/pattern/patkind-ref-binding-issue-122415.stderr7
-rw-r--r--tests/ui/unboxed-closures/unboxed-closure-immutable-capture.stderr63
-rw-r--r--tests/ui/unboxed-closures/unboxed-closures-infer-fnmut-calling-fnmut-no-mut.stderr7
-rw-r--r--tests/ui/unboxed-closures/unboxed-closures-mutate-upvar.stderr24
19 files changed, 244 insertions, 140 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
index 4174c75b284..677029f9d3f 100644
--- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
@@ -408,10 +408,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
                                     fn_decl.implicit_self,
                                     hir::ImplicitSelfKind::RefImm | hir::ImplicitSelfKind::RefMut
                                 ) {
-                                    err.span_suggestion(
-                                        upvar_ident.span,
+                                    err.span_suggestion_verbose(
+                                        upvar_ident.span.shrink_to_lo(),
                                         "consider changing this to be mutable",
-                                        format!("mut {}", upvar_ident.name),
+                                        "mut ",
                                         Applicability::MachineApplicable,
                                     );
                                     break;
@@ -419,10 +419,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
                             }
                         }
                     } else {
-                        err.span_suggestion(
-                            upvar_ident.span,
+                        err.span_suggestion_verbose(
+                            upvar_ident.span.shrink_to_lo(),
                             "consider changing this to be mutable",
-                            format!("mut {}", upvar_ident.name),
+                            "mut ",
                             Applicability::MachineApplicable,
                         );
                     }
@@ -755,13 +755,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
                 pat: hir::Pat { kind: hir::PatKind::Ref(_, _), .. },
                 ..
             }) = node
-            && let Ok(name) =
-                self.infcx.tcx.sess.source_map().span_to_snippet(local_decl.source_info.span)
         {
-            err.span_suggestion(
-                pat_span,
+            err.multipart_suggestion(
                 "consider changing this to be mutable",
-                format!("&(mut {name})"),
+                vec![
+                    (pat_span.until(local_decl.source_info.span), "&(mut ".to_string()),
+                    (
+                        local_decl.source_info.span.shrink_to_hi().with_hi(pat_span.hi()),
+                        ")".to_string(),
+                    ),
+                ],
                 Applicability::MachineApplicable,
             );
             return;
diff --git a/tests/ui/borrowck/borrow-raw-address-of-mutability.stderr b/tests/ui/borrowck/borrow-raw-address-of-mutability.stderr
index a7748209187..4b5b368287e 100644
--- a/tests/ui/borrowck/borrow-raw-address-of-mutability.stderr
+++ b/tests/ui/borrowck/borrow-raw-address-of-mutability.stderr
@@ -12,11 +12,13 @@ LL |     let mut x = 0;
 error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
   --> $DIR/borrow-raw-address-of-mutability.rs:11:17
    |
-LL |     let x = 0;
-   |         - help: consider changing this to be mutable: `mut x`
-LL |     let mut f = || {
 LL |         let y = &raw mut x;
    |                 ^^^^^^^^^^ cannot borrow as mutable
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut x = 0;
+   |         +++
 
 error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable
   --> $DIR/borrow-raw-address-of-mutability.rs:21:5
diff --git a/tests/ui/borrowck/borrowck-closures-unique.stderr b/tests/ui/borrowck/borrowck-closures-unique.stderr
index 23d3cc0e76f..613df9f2100 100644
--- a/tests/ui/borrowck/borrowck-closures-unique.stderr
+++ b/tests/ui/borrowck/borrowck-closures-unique.stderr
@@ -43,10 +43,13 @@ LL |     c1;
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/borrowck-closures-unique.rs:43:38
    |
-LL | fn e(x: &'static mut isize) {
-   |      - help: consider changing this to be mutable: `mut x`
 LL |     let c1 = |y: &'static mut isize| x = y;
    |                                      ^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL | fn e(mut x: &'static mut isize) {
+   |      +++
 
 error: aborting due to 4 previous errors
 
diff --git a/tests/ui/borrowck/issue-111554.stderr b/tests/ui/borrowck/issue-111554.stderr
index 6b7a42e4959..b3e8caae343 100644
--- a/tests/ui/borrowck/issue-111554.stderr
+++ b/tests/ui/borrowck/issue-111554.stderr
@@ -19,10 +19,13 @@ LL |         || bar(&mut self);
 error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
   --> $DIR/issue-111554.rs:21:16
    |
-LL |     pub fn quux(self) {
-   |                 ---- help: consider changing this to be mutable: `mut self`
 LL |         || bar(&mut self);
    |                ^^^^^^^^^ cannot borrow as mutable
+   |
+help: consider changing this to be mutable
+   |
+LL |     pub fn quux(mut self) {
+   |                 +++
 
 error: aborting due to 4 previous errors
 
diff --git a/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.stderr b/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.stderr
index 098a2964e9f..ff5ec1db346 100644
--- a/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.stderr
+++ b/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.stderr
@@ -44,56 +44,68 @@ LL |         borrowck_closures_unique::e(addr_of_mut!(X));
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:9:46
    |
-LL |     pub fn e(x: &'static mut isize) {
-   |              - help: consider changing this to be mutable: `mut x`
-LL |         static mut Y: isize = 3;
 LL |         let mut c1 = |y: &'static mut isize| x = y;
    |                                              ^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL |     pub fn e(mut x: &'static mut isize) {
+   |              +++
 
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:22:50
    |
-LL |     pub fn ee(x: &'static mut isize) {
-   |               - help: consider changing this to be mutable: `mut x`
-...
 LL |             let mut c2 = |y: &'static mut isize| x = y;
    |                                                  ^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL |     pub fn ee(mut x: &'static mut isize) {
+   |               +++
 
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:37:13
    |
-LL |     pub fn capture_assign_whole(x: (i32,)) {
-   |                                 - help: consider changing this to be mutable: `mut x`
-LL |         || {
 LL |             x = (1,);
    |             ^^^^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL |     pub fn capture_assign_whole(mut x: (i32,)) {
+   |                                 +++
 
 error[E0594]: cannot assign to `x.0`, as `x` is not declared as mutable
   --> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:43:13
    |
-LL |     pub fn capture_assign_part(x: (i32,)) {
-   |                                - help: consider changing this to be mutable: `mut x`
-LL |         || {
 LL |             x.0 = 1;
    |             ^^^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL |     pub fn capture_assign_part(mut x: (i32,)) {
+   |                                +++
 
 error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
   --> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:49:13
    |
-LL |     pub fn capture_reborrow_whole(x: (i32,)) {
-   |                                   - help: consider changing this to be mutable: `mut x`
-LL |         || {
 LL |             &mut x;
    |             ^^^^^^ cannot borrow as mutable
+   |
+help: consider changing this to be mutable
+   |
+LL |     pub fn capture_reborrow_whole(mut x: (i32,)) {
+   |                                   +++
 
 error[E0596]: cannot borrow `x.0` as mutable, as `x` is not declared as mutable
   --> $DIR/issue-55492-borrowck-migrate-scans-parents.rs:55:13
    |
-LL |     pub fn capture_reborrow_part(x: (i32,)) {
-   |                                  - help: consider changing this to be mutable: `mut x`
-LL |         || {
 LL |             &mut x.0;
    |             ^^^^^^^^ cannot borrow as mutable
+   |
+help: consider changing this to be mutable
+   |
+LL |     pub fn capture_reborrow_part(mut x: (i32,)) {
+   |                                  +++
 
 error: aborting due to 6 previous errors; 3 warnings emitted
 
diff --git a/tests/ui/borrowck/mutability-errors.stderr b/tests/ui/borrowck/mutability-errors.stderr
index b39e57d70ec..3cab3ccb993 100644
--- a/tests/ui/borrowck/mutability-errors.stderr
+++ b/tests/ui/borrowck/mutability-errors.stderr
@@ -262,74 +262,90 @@ LL | fn imm_local(mut x: (i32,)) {
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/mutability-errors.rs:60:9
    |
-LL | fn imm_capture(x: (i32,)) {
-   |                - help: consider changing this to be mutable: `mut x`
-LL |     || {
 LL |         x = (1,);
    |         ^^^^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL | fn imm_capture(mut x: (i32,)) {
+   |                +++
 
 error[E0594]: cannot assign to `x.0`, as `x` is not declared as mutable
   --> $DIR/mutability-errors.rs:61:9
    |
-LL | fn imm_capture(x: (i32,)) {
-   |                - help: consider changing this to be mutable: `mut x`
-...
 LL |         x.0 = 1;
    |         ^^^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL | fn imm_capture(mut x: (i32,)) {
+   |                +++
 
 error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
   --> $DIR/mutability-errors.rs:62:9
    |
-LL | fn imm_capture(x: (i32,)) {
-   |                - help: consider changing this to be mutable: `mut x`
-...
 LL |         &mut x;
    |         ^^^^^^ cannot borrow as mutable
+   |
+help: consider changing this to be mutable
+   |
+LL | fn imm_capture(mut x: (i32,)) {
+   |                +++
 
 error[E0596]: cannot borrow `x.0` as mutable, as `x` is not declared as mutable
   --> $DIR/mutability-errors.rs:63:9
    |
-LL | fn imm_capture(x: (i32,)) {
-   |                - help: consider changing this to be mutable: `mut x`
-...
 LL |         &mut x.0;
    |         ^^^^^^^^ cannot borrow as mutable
+   |
+help: consider changing this to be mutable
+   |
+LL | fn imm_capture(mut x: (i32,)) {
+   |                +++
 
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/mutability-errors.rs:66:9
    |
-LL | fn imm_capture(x: (i32,)) {
-   |                - help: consider changing this to be mutable: `mut x`
-...
 LL |         x = (1,);
    |         ^^^^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL | fn imm_capture(mut x: (i32,)) {
+   |                +++
 
 error[E0594]: cannot assign to `x.0`, as `x` is not declared as mutable
   --> $DIR/mutability-errors.rs:67:9
    |
-LL | fn imm_capture(x: (i32,)) {
-   |                - help: consider changing this to be mutable: `mut x`
-...
 LL |         x.0 = 1;
    |         ^^^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL | fn imm_capture(mut x: (i32,)) {
+   |                +++
 
 error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
   --> $DIR/mutability-errors.rs:68:9
    |
-LL | fn imm_capture(x: (i32,)) {
-   |                - help: consider changing this to be mutable: `mut x`
-...
 LL |         &mut x;
    |         ^^^^^^ cannot borrow as mutable
+   |
+help: consider changing this to be mutable
+   |
+LL | fn imm_capture(mut x: (i32,)) {
+   |                +++
 
 error[E0596]: cannot borrow `x.0` as mutable, as `x` is not declared as mutable
   --> $DIR/mutability-errors.rs:69:9
    |
-LL | fn imm_capture(x: (i32,)) {
-   |                - help: consider changing this to be mutable: `mut x`
-...
 LL |         &mut x.0;
    |         ^^^^^^^^ cannot borrow as mutable
+   |
+help: consider changing this to be mutable
+   |
+LL | fn imm_capture(mut x: (i32,)) {
+   |                +++
 
 error[E0594]: cannot assign to immutable static item `X`
   --> $DIR/mutability-errors.rs:76:5
diff --git a/tests/ui/cannot-mutate-captured-non-mut-var.stderr b/tests/ui/cannot-mutate-captured-non-mut-var.stderr
index 2d6e83c9e82..8d794f8251f 100644
--- a/tests/ui/cannot-mutate-captured-non-mut-var.stderr
+++ b/tests/ui/cannot-mutate-captured-non-mut-var.stderr
@@ -1,18 +1,24 @@
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/cannot-mutate-captured-non-mut-var.rs:9:25
    |
-LL |     let x = 1;
-   |         - help: consider changing this to be mutable: `mut x`
 LL |     to_fn_once(move|| { x = 2; });
    |                         ^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut x = 1;
+   |         +++
 
 error[E0596]: cannot borrow `s` as mutable, as it is not declared as mutable
   --> $DIR/cannot-mutate-captured-non-mut-var.rs:13:25
    |
-LL |     let s = std::io::stdin();
-   |         - help: consider changing this to be mutable: `mut s`
 LL |     to_fn_once(move|| { s.read_to_end(&mut Vec::new()); });
    |                         ^ cannot borrow as mutable
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut s = std::io::stdin();
+   |         +++
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/closures/2229_closure_analysis/array_subslice.stderr b/tests/ui/closures/2229_closure_analysis/array_subslice.stderr
index 888c60d5e91..ee941caa773 100644
--- a/tests/ui/closures/2229_closure_analysis/array_subslice.stderr
+++ b/tests/ui/closures/2229_closure_analysis/array_subslice.stderr
@@ -1,11 +1,13 @@
 error[E0596]: cannot borrow `x[..]` as mutable, as `x` is not declared as mutable
   --> $DIR/array_subslice.rs:7:21
    |
-LL | pub fn subslice_array(x: [u8; 3]) {
-   |                       - help: consider changing this to be mutable: `mut x`
-...
 LL |         let [ref y, ref mut z @ ..] = x;
    |                     ^^^^^^^^^ cannot borrow as mutable
+   |
+help: consider changing this to be mutable
+   |
+LL | pub fn subslice_array(mut x: [u8; 3]) {
+   |                       +++
 
 error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable
   --> $DIR/array_subslice.rs:10:5
diff --git a/tests/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm.stderr b/tests/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm.stderr
index 98414fa8a3d..6f5043ef08d 100644
--- a/tests/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm.stderr
+++ b/tests/ui/closures/2229_closure_analysis/diagnostics/cant-mutate-imm.stderr
@@ -1,20 +1,24 @@
 error[E0594]: cannot assign to `z.0.0.0`, as it is not declared as mutable
   --> $DIR/cant-mutate-imm.rs:12:9
    |
-LL |     let z = (y, 10);
-   |         - help: consider changing this to be mutable: `mut z`
-...
 LL |         z.0.0.0 = 20;
    |         ^^^^^^^^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut z = (y, 10);
+   |         +++
 
 error[E0594]: cannot assign to `*bx.0`, as it is not declared as mutable
   --> $DIR/cant-mutate-imm.rs:24:9
    |
-LL |     let bx = Box::new(x);
-   |         -- help: consider changing this to be mutable: `mut bx`
-...
 LL |         bx.0 = 20;
    |         ^^^^^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut bx = Box::new(x);
+   |         +++
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/closures/closure-immutable-outer-variable.stderr b/tests/ui/closures/closure-immutable-outer-variable.stderr
index 23bd0020db6..c4b0e544957 100644
--- a/tests/ui/closures/closure-immutable-outer-variable.stderr
+++ b/tests/ui/closures/closure-immutable-outer-variable.stderr
@@ -1,10 +1,13 @@
 error[E0594]: cannot assign to `y`, as it is not declared as mutable
   --> $DIR/closure-immutable-outer-variable.rs:11:26
    |
-LL |     let y = true;
-   |         - help: consider changing this to be mutable: `mut y`
 LL |     foo(Box::new(move || y = !y) as Box<_>);
    |                          ^^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut y = true;
+   |         +++
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/fn/suggest-return-closure.stderr b/tests/ui/fn/suggest-return-closure.stderr
index d276ce8be2b..45c12b548e6 100644
--- a/tests/ui/fn/suggest-return-closure.stderr
+++ b/tests/ui/fn/suggest-return-closure.stderr
@@ -34,11 +34,13 @@ LL | fn fun() -> _ {
 error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
   --> $DIR/suggest-return-closure.rs:23:9
    |
-LL |     let x = String::new();
-   |         - help: consider changing this to be mutable: `mut x`
-...
 LL |         x.push(c);
    |         ^ cannot borrow as mutable
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut x = String::new();
+   |         +++
 
 error[E0597]: `x` does not live long enough
   --> $DIR/suggest-return-closure.rs:23:9
diff --git a/tests/ui/nll/closure-captures.stderr b/tests/ui/nll/closure-captures.stderr
index 5233f0b2462..828974c517e 100644
--- a/tests/ui/nll/closure-captures.stderr
+++ b/tests/ui/nll/closure-captures.stderr
@@ -1,38 +1,46 @@
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/closure-captures.rs:7:5
    |
-LL | fn one_closure(x: i32) {
-   |                - help: consider changing this to be mutable: `mut x`
-LL |     ||
 LL |     x = 1;
    |     ^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL | fn one_closure(mut x: i32) {
+   |                +++
 
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/closure-captures.rs:9:5
    |
-LL | fn one_closure(x: i32) {
-   |                - help: consider changing this to be mutable: `mut x`
-...
 LL |     x = 1;
    |     ^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL | fn one_closure(mut x: i32) {
+   |                +++
 
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/closure-captures.rs:15:9
    |
-LL | fn two_closures(x: i32) {
-   |                 - help: consider changing this to be mutable: `mut x`
-...
 LL |         x = 1;
    |         ^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL | fn two_closures(mut x: i32) {
+   |                 +++
 
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/closure-captures.rs:19:9
    |
-LL | fn two_closures(x: i32) {
-   |                 - help: consider changing this to be mutable: `mut x`
-...
 LL |         x = 1;
    |         ^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL | fn two_closures(mut x: i32) {
+   |                 +++
 
 error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure
   --> $DIR/closure-captures.rs:27:9
@@ -67,11 +75,13 @@ LL |     x = 1;});
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/closure-captures.rs:39:10
    |
-LL | fn two_closures_ref(x: i32) {
-   |                     - help: consider changing this to be mutable: `mut x`
-...
 LL |          x = 1;}
    |          ^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL | fn two_closures_ref(mut x: i32) {
+   |                     +++
 
 error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure
   --> $DIR/closure-captures.rs:38:9
@@ -91,11 +101,13 @@ LL |          x = 1;}
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/closure-captures.rs:43:5
    |
-LL | fn two_closures_ref(x: i32) {
-   |                     - help: consider changing this to be mutable: `mut x`
-...
 LL |     x = 1;});
    |     ^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL | fn two_closures_ref(mut x: i32) {
+   |                     +++
 
 error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure
   --> $DIR/closure-captures.rs:42:9
diff --git a/tests/ui/nll/coroutine-upvar-mutability.stderr b/tests/ui/nll/coroutine-upvar-mutability.stderr
index 8b9be877c8f..02c01130176 100644
--- a/tests/ui/nll/coroutine-upvar-mutability.stderr
+++ b/tests/ui/nll/coroutine-upvar-mutability.stderr
@@ -1,11 +1,13 @@
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/coroutine-upvar-mutability.rs:10:9
    |
-LL |     let x = 0;
-   |         - help: consider changing this to be mutable: `mut x`
-...
 LL |         x = 1;
    |         ^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut x = 0;
+   |         +++
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/nll/issue-46023.stderr b/tests/ui/nll/issue-46023.stderr
index 062e07407ce..d071c29271c 100644
--- a/tests/ui/nll/issue-46023.stderr
+++ b/tests/ui/nll/issue-46023.stderr
@@ -1,11 +1,13 @@
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/issue-46023.rs:5:9
    |
-LL |     let x = 0;
-   |         - help: consider changing this to be mutable: `mut x`
-...
 LL |         x = 1;
    |         ^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut x = 0;
+   |         +++
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/pattern/patkind-ref-binding-issue-114896.stderr b/tests/ui/pattern/patkind-ref-binding-issue-114896.stderr
index 68538255edd..e9c2fccaba2 100644
--- a/tests/ui/pattern/patkind-ref-binding-issue-114896.stderr
+++ b/tests/ui/pattern/patkind-ref-binding-issue-114896.stderr
@@ -1,10 +1,13 @@
 error[E0596]: cannot borrow `b` as mutable, as it is not declared as mutable
   --> $DIR/patkind-ref-binding-issue-114896.rs:7:9
    |
-LL |         let &b = a;
-   |             -- help: consider changing this to be mutable: `&(mut b)`
 LL |         b.make_ascii_uppercase();
    |         ^ cannot borrow as mutable
+   |
+help: consider changing this to be mutable
+   |
+LL |         let &(mut b) = a;
+   |             ~~~~~  +
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/pattern/patkind-ref-binding-issue-122415.stderr b/tests/ui/pattern/patkind-ref-binding-issue-122415.stderr
index 39283133ac7..e93b8bbaccc 100644
--- a/tests/ui/pattern/patkind-ref-binding-issue-122415.stderr
+++ b/tests/ui/pattern/patkind-ref-binding-issue-122415.stderr
@@ -1,10 +1,13 @@
 error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
   --> $DIR/patkind-ref-binding-issue-122415.rs:7:12
    |
-LL | fn foo(&x: &i32) {
-   |        -- help: consider changing this to be mutable: `&(mut x)`
 LL |     mutate(&mut x);
    |            ^^^^^^ cannot borrow as mutable
+   |
+help: consider changing this to be mutable
+   |
+LL | fn foo(&(mut x): &i32) {
+   |        ~~~~~  +
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/unboxed-closures/unboxed-closure-immutable-capture.stderr b/tests/ui/unboxed-closures/unboxed-closure-immutable-capture.stderr
index ad5451ced55..04f9ab246b3 100644
--- a/tests/ui/unboxed-closures/unboxed-closure-immutable-capture.stderr
+++ b/tests/ui/unboxed-closures/unboxed-closure-immutable-capture.stderr
@@ -1,73 +1,90 @@
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/unboxed-closure-immutable-capture.rs:9:13
    |
-LL |     let x = 0;
-   |         - help: consider changing this to be mutable: `mut x`
 LL |     move || x = 1;
    |             ^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut x = 0;
+   |         +++
 
 error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
   --> $DIR/unboxed-closure-immutable-capture.rs:10:17
    |
-LL |     let x = 0;
-   |         - help: consider changing this to be mutable: `mut x`
-LL |     move || x = 1;
 LL |     move || set(&mut x);
    |                 ^^^^^^ cannot borrow as mutable
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut x = 0;
+   |         +++
 
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/unboxed-closure-immutable-capture.rs:11:13
    |
-LL |     let x = 0;
-   |         - help: consider changing this to be mutable: `mut x`
-...
 LL |     move || x = 1;
    |             ^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut x = 0;
+   |         +++
 
 error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
   --> $DIR/unboxed-closure-immutable-capture.rs:12:17
    |
-LL |     let x = 0;
-   |         - help: consider changing this to be mutable: `mut x`
-...
 LL |     move || set(&mut x);
    |                 ^^^^^^ cannot borrow as mutable
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut x = 0;
+   |         +++
 
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/unboxed-closure-immutable-capture.rs:13:8
    |
-LL |     let x = 0;
-   |         - help: consider changing this to be mutable: `mut x`
-...
 LL |     || x = 1;
    |        ^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut x = 0;
+   |         +++
 
 error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
   --> $DIR/unboxed-closure-immutable-capture.rs:14:12
    |
-LL |     let x = 0;
-   |         - help: consider changing this to be mutable: `mut x`
-...
 LL |     || set(&mut x);
    |            ^^^^^^ cannot borrow as mutable
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut x = 0;
+   |         +++
 
 error[E0594]: cannot assign to `x`, as it is not declared as mutable
   --> $DIR/unboxed-closure-immutable-capture.rs:15:8
    |
-LL |     let x = 0;
-   |         - help: consider changing this to be mutable: `mut x`
-...
 LL |     || x = 1;
    |        ^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut x = 0;
+   |         +++
 
 error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
   --> $DIR/unboxed-closure-immutable-capture.rs:16:12
    |
-LL |     let x = 0;
-   |         - help: consider changing this to be mutable: `mut x`
-...
 LL |     || set(&mut x);
    |            ^^^^^^ cannot borrow as mutable
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut x = 0;
+   |         +++
 
 error: aborting due to 8 previous errors
 
diff --git a/tests/ui/unboxed-closures/unboxed-closures-infer-fnmut-calling-fnmut-no-mut.stderr b/tests/ui/unboxed-closures/unboxed-closures-infer-fnmut-calling-fnmut-no-mut.stderr
index 5c93ed6d7f7..07c66276eaf 100644
--- a/tests/ui/unboxed-closures/unboxed-closures-infer-fnmut-calling-fnmut-no-mut.stderr
+++ b/tests/ui/unboxed-closures/unboxed-closures-infer-fnmut-calling-fnmut-no-mut.stderr
@@ -1,13 +1,16 @@
 error[E0596]: cannot borrow `tick1` as mutable, as it is not declared as mutable
   --> $DIR/unboxed-closures-infer-fnmut-calling-fnmut-no-mut.rs:16:9
    |
-LL |     let tick1 = || {
-   |         ----- help: consider changing this to be mutable: `mut tick1`
 LL |         counter += 1;
    |         ------- calling `tick1` requires mutable binding due to mutable borrow of `counter`
 ...
 LL |         tick1();
    |         ^^^^^ cannot borrow as mutable
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut tick1 = || {
+   |         +++
 
 error[E0596]: cannot borrow `tick2` as mutable, as it is not declared as mutable
   --> $DIR/unboxed-closures-infer-fnmut-calling-fnmut-no-mut.rs:19:5
diff --git a/tests/ui/unboxed-closures/unboxed-closures-mutate-upvar.stderr b/tests/ui/unboxed-closures/unboxed-closures-mutate-upvar.stderr
index 26f97b51913..80caddb2a11 100644
--- a/tests/ui/unboxed-closures/unboxed-closures-mutate-upvar.stderr
+++ b/tests/ui/unboxed-closures/unboxed-closures-mutate-upvar.stderr
@@ -1,29 +1,35 @@
 error[E0594]: cannot assign to `n`, as it is not declared as mutable
   --> $DIR/unboxed-closures-mutate-upvar.rs:15:9
    |
-LL |     let n = 0;
-   |         - help: consider changing this to be mutable: `mut n`
-LL |     let mut f = to_fn_mut(|| {
 LL |         n += 1;
    |         ^^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut n = 0;
+   |         +++
 
 error[E0594]: cannot assign to `n`, as it is not declared as mutable
   --> $DIR/unboxed-closures-mutate-upvar.rs:32:9
    |
-LL |     let n = 0;
-   |         - help: consider changing this to be mutable: `mut n`
-...
 LL |         n += 1;
    |         ^^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut n = 0;
+   |         +++
 
 error[E0594]: cannot assign to `n`, as it is not declared as mutable
   --> $DIR/unboxed-closures-mutate-upvar.rs:46:9
    |
-LL |     let n = 0;
-   |         - help: consider changing this to be mutable: `mut n`
-LL |     let mut f = to_fn(move || {
 LL |         n += 1;
    |         ^^^^^^ cannot assign
+   |
+help: consider changing this to be mutable
+   |
+LL |     let mut n = 0;
+   |         +++
 
 error[E0594]: cannot assign to `n`, as it is a captured variable in a `Fn` closure
   --> $DIR/unboxed-closures-mutate-upvar.rs:53:9