diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 3319a80681fde..05c718d580205 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -333,7 +333,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let local_decl = &self.body.local_decls[local]; assert_eq!(local_decl.mutability, Mutability::Not); - err.span_label(span, format!("cannot {ACT}", ACT = act)); + err.span_label(span, format!("cannot {act}")); err.span_suggestion( local_decl.source_info.span, "consider changing this to be mutable", @@ -357,7 +357,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let captured_place = &self.upvars[upvar_index.index()].place; - err.span_label(span, format!("cannot {ACT}", ACT = act)); + err.span_label(span, format!("cannot {act}")); let upvar_hir_id = captured_place.get_root_variable(); @@ -397,7 +397,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { .span_to_snippet(span) .map_or(false, |snippet| snippet.starts_with("&mut ")) => { - err.span_label(span, format!("cannot {ACT}", ACT = act)); + err.span_label(span, format!("cannot {act}")); err.span_suggestion( span, "try removing `&mut` here", @@ -409,7 +409,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { PlaceRef { local, projection: [ProjectionElem::Deref] } if self.body.local_decls[local].is_ref_for_guard() => { - err.span_label(span, format!("cannot {ACT}", ACT = act)); + err.span_label(span, format!("cannot {act}")); err.note( "variables bound in patterns are immutable until the end of the pattern guard", ); @@ -537,7 +537,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { Some((true, err_help_span, suggested_code)) => { let (is_trait_sig, local_trait) = self.is_error_in_trait(local); if !is_trait_sig { - err.span_suggestion( + err.span_suggestion_verbose( err_help_span, &format!( "consider changing this to be a mutable {pointer_desc}" @@ -546,7 +546,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { Applicability::MachineApplicable, ); } else if let Some(x) = local_trait { - err.span_suggestion( + err.span_suggestion_verbose( x, &format!( "consider changing that to be a mutable {pointer_desc}" @@ -569,24 +569,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { err.span_label( span, format!( - "`{NAME}` is a `{SIGIL}` {DESC}, \ - so the data it refers to cannot be {ACTED_ON}", - NAME = name, - SIGIL = pointer_sigil, - DESC = pointer_desc, - ACTED_ON = acted_on + "`{name}` is a `{pointer_sigil}` {pointer_desc}, \ + so the data it refers to cannot be {acted_on}", ), ); } _ => { err.span_label( span, - format!( - "cannot {ACT} through `{SIGIL}` {DESC}", - ACT = act, - SIGIL = pointer_sigil, - DESC = pointer_desc - ), + format!("cannot {act} through `{pointer_sigil}` {pointer_desc}"), ); } } @@ -605,13 +596,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { Some(BorrowedContentSource::OverloadedDeref(ty)) => { err.help(&format!( "trait `DerefMut` is required to modify through a dereference, \ - but it is not implemented for `{ty}`", + but it is not implemented for `{ty}`", )); } Some(BorrowedContentSource::OverloadedIndex(ty)) => { err.help(&format!( "trait `IndexMut` is required to modify indexed content, \ - but it is not implemented for `{ty}`", + but it is not implemented for `{ty}`", )); self.suggest_map_index_mut_alternatives(ty, &mut err, span); } @@ -620,7 +611,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } _ => { - err.span_label(span, format!("cannot {ACT}", ACT = act)); + err.span_label(span, format!("cannot {act}")); } } diff --git a/src/test/ui/array-slice-vec/slice-mut-2.stderr b/src/test/ui/array-slice-vec/slice-mut-2.stderr index bad0268772b79..5b040d3e4d31d 100644 --- a/src/test/ui/array-slice-vec/slice-mut-2.stderr +++ b/src/test/ui/array-slice-vec/slice-mut-2.stderr @@ -1,11 +1,13 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/slice-mut-2.rs:7:18 | -LL | let x: &[isize] = &[1, 2, 3, 4, 5]; - | ---------------- help: consider changing this to be a mutable reference: `&mut [1, 2, 3, 4, 5]` -... LL | let _ = &mut x[2..4]; | ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | let x: &[isize] = &mut [1, 2, 3, 4, 5]; + | ~~~~~~~~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/borrowck/borrow-raw-address-of-deref-mutability.stderr b/src/test/ui/borrowck/borrow-raw-address-of-deref-mutability.stderr index 5963dab9f4aab..4cc1d821d0a06 100644 --- a/src/test/ui/borrowck/borrow-raw-address-of-deref-mutability.stderr +++ b/src/test/ui/borrowck/borrow-raw-address-of-deref-mutability.stderr @@ -1,20 +1,24 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrow-raw-address-of-deref-mutability.rs:8:13 | -LL | let x = &0; - | -- help: consider changing this to be a mutable reference: `&mut 0` -LL | LL | let q = &raw mut *x; | ^^^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | let x = &mut 0; + | ~~~~~~ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `*const` pointer --> $DIR/borrow-raw-address-of-deref-mutability.rs:14:13 | -LL | let x = &0 as *const i32; - | -- help: consider changing this to be a mutable pointer: `&mut 0` -LL | LL | let q = &raw mut *x; | ^^^^^^^^^^^ `x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable pointer + | +LL | let x = &mut 0 as *const i32; + | ~~~~~~ error: aborting due to 2 previous errors diff --git a/src/test/ui/borrowck/borrowck-access-permissions.stderr b/src/test/ui/borrowck/borrowck-access-permissions.stderr index e3a35c38a7c03..312720898473a 100644 --- a/src/test/ui/borrowck/borrowck-access-permissions.stderr +++ b/src/test/ui/borrowck/borrowck-access-permissions.stderr @@ -25,28 +25,35 @@ LL | let _y1 = &mut *box_x; error[E0596]: cannot borrow `*ref_x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-access-permissions.rs:30:19 | -LL | let ref_x = &x; - | -- help: consider changing this to be a mutable reference: `&mut x` -... LL | let _y1 = &mut *ref_x; | ^^^^^^^^^^^ `ref_x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | let ref_x = &mut x; + | ~~~~~~ error[E0596]: cannot borrow `*ptr_x` as mutable, as it is behind a `*const` pointer --> $DIR/borrowck-access-permissions.rs:39:23 | -LL | let ptr_x : *const _ = &x; - | -- help: consider changing this to be a mutable pointer: `&mut x` -... LL | let _y1 = &mut *ptr_x; | ^^^^^^^^^^^ `ptr_x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable pointer + | +LL | let ptr_x : *const _ = &mut x; + | ~~~~~~ error[E0596]: cannot borrow `*foo_ref.f` as mutable, as it is behind a `&` reference --> $DIR/borrowck-access-permissions.rs:48:18 | -LL | let foo_ref = &foo; - | ---- help: consider changing this to be a mutable reference: `&mut foo` LL | let _y = &mut *foo_ref.f; | ^^^^^^^^^^^^^^^ `foo_ref` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | let foo_ref = &mut foo; + | ~~~~~~~~ error: aborting due to 6 previous errors diff --git a/src/test/ui/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.stderr b/src/test/ui/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.stderr index 0475df447445d..cbacc87a0e858 100644 --- a/src/test/ui/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.stderr +++ b/src/test/ui/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.stderr @@ -1,18 +1,24 @@ error[E0594]: cannot assign to `*s.pointer`, which is behind a `&` reference --> $DIR/borrowck-assign-to-andmut-in-aliasable-loc.rs:9:5 | -LL | fn a(s: &S) { - | -- help: consider changing this to be a mutable reference: `&mut S<'_>` LL | *s.pointer += 1; | ^^^^^^^^^^^^^^^ `s` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | fn a(s: &mut S<'_>) { + | ~~~~~~~~~~ error[E0594]: cannot assign to `*s.pointer`, which is behind a `&` reference --> $DIR/borrowck-assign-to-andmut-in-aliasable-loc.rs:17:5 | -LL | fn c(s: & &mut S) { - | -------- help: consider changing this to be a mutable reference: `&mut &mut S<'_>` LL | *s.pointer += 1; | ^^^^^^^^^^^^^^^ `s` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | fn c(s: &mut &mut S<'_>) { + | ~~~~~~~~~~~~~~~ error: aborting due to 2 previous errors diff --git a/src/test/ui/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.stderr b/src/test/ui/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.stderr index c99c0f77982ed..ce9f7aa050a0a 100644 --- a/src/test/ui/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.stderr +++ b/src/test/ui/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.stderr @@ -20,10 +20,13 @@ LL | **t1 = 22; error[E0596]: cannot borrow `**t0` as mutable, as it is behind a `&` reference --> $DIR/borrowck-borrow-mut-base-ptr-in-aliasable-loc.rs:19:26 | -LL | fn foo4(t0: & &mut isize) { - | ------------ help: consider changing this to be a mutable reference: `&mut &mut isize` LL | let x: &mut isize = &mut **t0; | ^^^^^^^^^ `t0` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn foo4(t0: &mut &mut isize) { + | ~~~~~~~~~~~~~~~ error: aborting due to 3 previous errors diff --git a/src/test/ui/borrowck/borrowck-issue-14498.stderr b/src/test/ui/borrowck/borrowck-issue-14498.stderr index 4c0e46d453142..42a55b7a854ba 100644 --- a/src/test/ui/borrowck/borrowck-issue-14498.stderr +++ b/src/test/ui/borrowck/borrowck-issue-14498.stderr @@ -1,10 +1,13 @@ error[E0594]: cannot assign to `***p`, which is behind a `&` reference --> $DIR/borrowck-issue-14498.rs:16:5 | -LL | let p = &y; - | -- help: consider changing this to be a mutable reference: `&mut y` LL | ***p = 2; | ^^^^^^^^ `p` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | let p = &mut y; + | ~~~~~~ error[E0506]: cannot assign to `**y` because it is borrowed --> $DIR/borrowck-issue-14498.rs:25:5 diff --git a/src/test/ui/borrowck/borrowck-reborrow-from-mut.stderr b/src/test/ui/borrowck/borrowck-reborrow-from-mut.stderr index 284cab2960842..d9590e446c756 100644 --- a/src/test/ui/borrowck/borrowck-reborrow-from-mut.stderr +++ b/src/test/ui/borrowck/borrowck-reborrow-from-mut.stderr @@ -105,10 +105,13 @@ LL | use_imm(_bar1); error[E0596]: cannot borrow `foo.bar1` as mutable, as it is behind a `&` reference --> $DIR/borrowck-reborrow-from-mut.rs:88:17 | -LL | fn borrow_mut_from_imm(foo: &Foo) { - | ---- help: consider changing this to be a mutable reference: `&mut Foo` LL | let _bar1 = &mut foo.bar1; | ^^^^^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn borrow_mut_from_imm(foo: &mut Foo) { + | ~~~~~~~~ error: aborting due to 11 previous errors diff --git a/src/test/ui/borrowck/issue-85765.stderr b/src/test/ui/borrowck/issue-85765.stderr index 13033962142fa..7da7dba68ab7a 100644 --- a/src/test/ui/borrowck/issue-85765.stderr +++ b/src/test/ui/borrowck/issue-85765.stderr @@ -10,11 +10,13 @@ LL | rofl.push(Vec::new()); error[E0594]: cannot assign to `*r`, which is behind a `&` reference --> $DIR/issue-85765.rs:12:5 | -LL | let r = &mutvar; - | ------- help: consider changing this to be a mutable reference: `&mut mutvar` -LL | LL | *r = 0; | ^^^^^^ `r` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | let r = &mut mutvar; + | ~~~~~~~~~~~ error[E0594]: cannot assign to `*x`, which is behind a `&` reference --> $DIR/issue-85765.rs:19:5 diff --git a/src/test/ui/borrowck/issue-93093.stderr b/src/test/ui/borrowck/issue-93093.stderr index 031128af47655..afa76594f0b5e 100644 --- a/src/test/ui/borrowck/issue-93093.stderr +++ b/src/test/ui/borrowck/issue-93093.stderr @@ -1,11 +1,13 @@ error[E0594]: cannot assign to `self.foo`, which is behind a `&` reference --> $DIR/issue-93093.rs:8:9 | -LL | async fn bar(&self) { - | ----- help: consider changing this to be a mutable reference: `&mut self` -LL | LL | self.foo += 1; | ^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | async fn bar(&mut self) { + | ~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/borrowck/mutability-errors.stderr b/src/test/ui/borrowck/mutability-errors.stderr index dd29ae492d604..7a00ace3bb220 100644 --- a/src/test/ui/borrowck/mutability-errors.stderr +++ b/src/test/ui/borrowck/mutability-errors.stderr @@ -1,37 +1,46 @@ error[E0594]: cannot assign to `*x`, which is behind a `&` reference --> $DIR/mutability-errors.rs:9:5 | -LL | fn named_ref(x: &(i32,)) { - | ------- help: consider changing this to be a mutable reference: `&mut (i32,)` LL | *x = (1,); | ^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | fn named_ref(x: &mut (i32,)) { + | ~~~~~~~~~~~ error[E0594]: cannot assign to `x.0`, which is behind a `&` reference --> $DIR/mutability-errors.rs:10:5 | -LL | fn named_ref(x: &(i32,)) { - | ------- help: consider changing this to be a mutable reference: `&mut (i32,)` -LL | *x = (1,); LL | x.0 = 1; | ^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | fn named_ref(x: &mut (i32,)) { + | ~~~~~~~~~~~ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/mutability-errors.rs:11:5 | -LL | fn named_ref(x: &(i32,)) { - | ------- help: consider changing this to be a mutable reference: `&mut (i32,)` -... LL | &mut *x; | ^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn named_ref(x: &mut (i32,)) { + | ~~~~~~~~~~~ error[E0596]: cannot borrow `x.0` as mutable, as it is behind a `&` reference --> $DIR/mutability-errors.rs:12:5 | -LL | fn named_ref(x: &(i32,)) { - | ------- help: consider changing this to be a mutable reference: `&mut (i32,)` -... LL | &mut x.0; | ^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn named_ref(x: &mut (i32,)) { + | ~~~~~~~~~~~ error[E0594]: cannot assign to data in a `&` reference --> $DIR/mutability-errors.rs:16:5 @@ -60,37 +69,46 @@ LL | &mut f().0; error[E0594]: cannot assign to `*x`, which is behind a `*const` pointer --> $DIR/mutability-errors.rs:23:5 | -LL | unsafe fn named_ptr(x: *const (i32,)) { - | ------------- help: consider changing this to be a mutable pointer: `*mut (i32,)` LL | *x = (1,); | ^^^^^^^^^ `x` is a `*const` pointer, so the data it refers to cannot be written + | +help: consider changing this to be a mutable pointer + | +LL | unsafe fn named_ptr(x: *mut (i32,)) { + | ~~~~~~~~~~~ error[E0594]: cannot assign to `x.0`, which is behind a `*const` pointer --> $DIR/mutability-errors.rs:24:5 | -LL | unsafe fn named_ptr(x: *const (i32,)) { - | ------------- help: consider changing this to be a mutable pointer: `*mut (i32,)` -LL | *x = (1,); LL | (*x).0 = 1; | ^^^^^^^^^^ `x` is a `*const` pointer, so the data it refers to cannot be written + | +help: consider changing this to be a mutable pointer + | +LL | unsafe fn named_ptr(x: *mut (i32,)) { + | ~~~~~~~~~~~ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `*const` pointer --> $DIR/mutability-errors.rs:25:5 | -LL | unsafe fn named_ptr(x: *const (i32,)) { - | ------------- help: consider changing this to be a mutable pointer: `*mut (i32,)` -... LL | &mut *x; | ^^^^^^^ `x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable pointer + | +LL | unsafe fn named_ptr(x: *mut (i32,)) { + | ~~~~~~~~~~~ error[E0596]: cannot borrow `x.0` as mutable, as it is behind a `*const` pointer --> $DIR/mutability-errors.rs:26:5 | -LL | unsafe fn named_ptr(x: *const (i32,)) { - | ------------- help: consider changing this to be a mutable pointer: `*mut (i32,)` -... LL | &mut (*x).0; | ^^^^^^^^^^^ `x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable pointer + | +LL | unsafe fn named_ptr(x: *mut (i32,)) { + | ~~~~~~~~~~~ error[E0594]: cannot assign to data in a `*const` pointer --> $DIR/mutability-errors.rs:30:5 diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/mut_ref.stderr b/src/test/ui/closures/2229_closure_analysis/diagnostics/mut_ref.stderr index 481d7e58529ee..95f36fc042c4f 100644 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/mut_ref.stderr +++ b/src/test/ui/closures/2229_closure_analysis/diagnostics/mut_ref.stderr @@ -1,14 +1,16 @@ error[E0596]: cannot borrow `**ref_mref_x` as mutable, as it is behind a `&` reference --> $DIR/mut_ref.rs:12:13 | -LL | let ref_mref_x = &mref_x; - | ------- help: consider changing this to be a mutable reference: `&mut mref_x` -LL | LL | let c = || { | ^^ `ref_mref_x` is a `&` reference, so the data it refers to cannot be borrowed as mutable LL | LL | **ref_mref_x = y; | ------------ mutable borrow occurs due to use of `**ref_mref_x` in closure + | +help: consider changing this to be a mutable reference + | +LL | let ref_mref_x = &mut mref_x; + | ~~~~~~~~~~~ error[E0596]: cannot borrow `**mref_ref_x` as mutable, as it is behind a `&` reference --> $DIR/mut_ref.rs:26:13 diff --git a/src/test/ui/did_you_mean/issue-38147-1.stderr b/src/test/ui/did_you_mean/issue-38147-1.stderr index dd193458b3726..74fb1c2eca307 100644 --- a/src/test/ui/did_you_mean/issue-38147-1.stderr +++ b/src/test/ui/did_you_mean/issue-38147-1.stderr @@ -1,10 +1,13 @@ error[E0596]: cannot borrow `*self.s` as mutable, as it is behind a `&` reference --> $DIR/issue-38147-1.rs:17:9 | -LL | fn f(&self) { - | ----- help: consider changing this to be a mutable reference: `&mut self` LL | self.s.push('x'); | ^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn f(&mut self) { + | ~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/did_you_mean/issue-38147-4.stderr b/src/test/ui/did_you_mean/issue-38147-4.stderr index a2d162f08a173..d333998936169 100644 --- a/src/test/ui/did_you_mean/issue-38147-4.stderr +++ b/src/test/ui/did_you_mean/issue-38147-4.stderr @@ -1,10 +1,13 @@ error[E0596]: cannot borrow `*f.s` as mutable, as it is behind a `&` reference --> $DIR/issue-38147-4.rs:6:5 | -LL | fn f(x: usize, f: &Foo) { - | ---- help: consider changing this to be a mutable reference: `&mut Foo<'_>` LL | f.s.push('x'); | ^^^^^^^^^^^^^ `f` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn f(x: usize, f: &mut Foo<'_>) { + | ~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/did_you_mean/issue-39544.stderr b/src/test/ui/did_you_mean/issue-39544.stderr index 68180eaee036c..b16309af0418d 100644 --- a/src/test/ui/did_you_mean/issue-39544.stderr +++ b/src/test/ui/did_you_mean/issue-39544.stderr @@ -9,69 +9,90 @@ LL | let _ = &mut z.x; error[E0596]: cannot borrow `self.x` as mutable, as it is behind a `&` reference --> $DIR/issue-39544.rs:16:17 | -LL | fn foo<'z>(&'z self) { - | -------- help: consider changing this to be a mutable reference: `&'z mut self` LL | let _ = &mut self.x; | ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn foo<'z>(&'z mut self) { + | ~~~~~~~~~~~~ error[E0596]: cannot borrow `self.x` as mutable, as it is behind a `&` reference --> $DIR/issue-39544.rs:20:17 | -LL | fn foo1(&self, other: &Z) { - | ----- help: consider changing this to be a mutable reference: `&mut self` LL | let _ = &mut self.x; | ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn foo1(&mut self, other: &Z) { + | ~~~~~~~~~ error[E0596]: cannot borrow `other.x` as mutable, as it is behind a `&` reference --> $DIR/issue-39544.rs:21:17 | -LL | fn foo1(&self, other: &Z) { - | -- help: consider changing this to be a mutable reference: `&mut Z` -LL | let _ = &mut self.x; LL | let _ = &mut other.x; | ^^^^^^^^^^^^ `other` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn foo1(&self, other: &mut Z) { + | ~~~~~~ error[E0596]: cannot borrow `self.x` as mutable, as it is behind a `&` reference --> $DIR/issue-39544.rs:25:17 | -LL | fn foo2<'a>(&'a self, other: &Z) { - | -------- help: consider changing this to be a mutable reference: `&'a mut self` LL | let _ = &mut self.x; | ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn foo2<'a>(&'a mut self, other: &Z) { + | ~~~~~~~~~~~~ error[E0596]: cannot borrow `other.x` as mutable, as it is behind a `&` reference --> $DIR/issue-39544.rs:26:17 | -LL | fn foo2<'a>(&'a self, other: &Z) { - | -- help: consider changing this to be a mutable reference: `&mut Z` -LL | let _ = &mut self.x; LL | let _ = &mut other.x; | ^^^^^^^^^^^^ `other` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn foo2<'a>(&'a self, other: &mut Z) { + | ~~~~~~ error[E0596]: cannot borrow `self.x` as mutable, as it is behind a `&` reference --> $DIR/issue-39544.rs:30:17 | -LL | fn foo3<'a>(self: &'a Self, other: &Z) { - | -------- help: consider changing this to be a mutable reference: `&'a mut Self` LL | let _ = &mut self.x; | ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn foo3<'a>(self: &'a mut Self, other: &Z) { + | ~~~~~~~~~~~~ error[E0596]: cannot borrow `other.x` as mutable, as it is behind a `&` reference --> $DIR/issue-39544.rs:31:17 | -LL | fn foo3<'a>(self: &'a Self, other: &Z) { - | -- help: consider changing this to be a mutable reference: `&mut Z` -LL | let _ = &mut self.x; LL | let _ = &mut other.x; | ^^^^^^^^^^^^ `other` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn foo3<'a>(self: &'a Self, other: &mut Z) { + | ~~~~~~ error[E0596]: cannot borrow `other.x` as mutable, as it is behind a `&` reference --> $DIR/issue-39544.rs:35:17 | -LL | fn foo4(other: &Z) { - | -- help: consider changing this to be a mutable reference: `&mut Z` LL | let _ = &mut other.x; | ^^^^^^^^^^^^ `other` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn foo4(other: &mut Z) { + | ~~~~~~ error[E0596]: cannot borrow `z.x` as mutable, as `z` is not declared as mutable --> $DIR/issue-39544.rs:41:13 @@ -84,11 +105,13 @@ LL | let _ = &mut z.x; error[E0596]: cannot borrow `w.x` as mutable, as it is behind a `&` reference --> $DIR/issue-39544.rs:42:13 | -LL | pub fn with_arg(z: Z, w: &Z) { - | -- help: consider changing this to be a mutable reference: `&mut Z` -LL | let _ = &mut z.x; LL | let _ = &mut w.x; | ^^^^^^^^ `w` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | pub fn with_arg(z: Z, w: &mut Z) { + | ~~~~~~ error[E0594]: cannot assign to `*x.0`, which is behind a `&` reference --> $DIR/issue-39544.rs:48:5 diff --git a/src/test/ui/did_you_mean/issue-40823.stderr b/src/test/ui/did_you_mean/issue-40823.stderr index 67703a1497f50..aadd698891edc 100644 --- a/src/test/ui/did_you_mean/issue-40823.stderr +++ b/src/test/ui/did_you_mean/issue-40823.stderr @@ -1,10 +1,13 @@ error[E0596]: cannot borrow `*buf` as mutable, as it is behind a `&` reference --> $DIR/issue-40823.rs:3:5 | -LL | let mut buf = &[1, 2, 3, 4]; - | ------------- help: consider changing this to be a mutable reference: `&mut [1, 2, 3, 4]` LL | buf.iter_mut(); | ^^^^^^^^^^^^^^ `buf` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | let mut buf = &mut [1, 2, 3, 4]; + | ~~~~~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0389.stderr b/src/test/ui/error-codes/E0389.stderr index 3d615bd932f43..51c4c92addf28 100644 --- a/src/test/ui/error-codes/E0389.stderr +++ b/src/test/ui/error-codes/E0389.stderr @@ -1,10 +1,13 @@ error[E0594]: cannot assign to `fancy_ref.num`, which is behind a `&` reference --> $DIR/E0389.rs:8:5 | -LL | let fancy_ref = &(&mut fancy); - | ------------- help: consider changing this to be a mutable reference: `&mut (&mut fancy)` LL | fancy_ref.num = 6; | ^^^^^^^^^^^^^^^^^ `fancy_ref` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | let fancy_ref = &mut (&mut fancy); + | ~~~~~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-51515.stderr b/src/test/ui/issues/issue-51515.stderr index 067bdef8b6746..c4e61e7195392 100644 --- a/src/test/ui/issues/issue-51515.stderr +++ b/src/test/ui/issues/issue-51515.stderr @@ -1,11 +1,13 @@ error[E0594]: cannot assign to `*foo`, which is behind a `&` reference --> $DIR/issue-51515.rs:5:5 | -LL | let foo = &16; - | --- help: consider changing this to be a mutable reference: `&mut 16` -... LL | *foo = 32; | ^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | let foo = &mut 16; + | ~~~~~~~ error[E0594]: cannot assign to `*bar`, which is behind a `&` reference --> $DIR/issue-51515.rs:8:5 diff --git a/src/test/ui/issues/issue-61623.stderr b/src/test/ui/issues/issue-61623.stderr index f654605423379..5fcc338557c58 100644 --- a/src/test/ui/issues/issue-61623.stderr +++ b/src/test/ui/issues/issue-61623.stderr @@ -1,10 +1,13 @@ error[E0596]: cannot borrow `*x.1` as mutable, as it is behind a `&` reference --> $DIR/issue-61623.rs:6:19 | -LL | fn f3<'a>(x: &'a ((), &'a mut ())) { - | -------------------- help: consider changing this to be a mutable reference: `&'a mut ((), &'a mut ())` LL | f2(|| x.0, f1(x.1)) | ^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn f3<'a>(x: &'a mut ((), &'a mut ())) { + | ~~~~~~~~~~~~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/mut/mutable-class-fields-2.stderr b/src/test/ui/mut/mutable-class-fields-2.stderr index 5a4e31947f2b2..c53c6ea302c67 100644 --- a/src/test/ui/mut/mutable-class-fields-2.stderr +++ b/src/test/ui/mut/mutable-class-fields-2.stderr @@ -1,10 +1,13 @@ error[E0594]: cannot assign to `self.how_hungry`, which is behind a `&` reference --> $DIR/mutable-class-fields-2.rs:9:5 | -LL | pub fn eat(&self) { - | ----- help: consider changing this to be a mutable reference: `&mut self` LL | self.how_hungry -= 5; | ^^^^^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | pub fn eat(&mut self) { + | ~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/nll/issue-47388.stderr b/src/test/ui/nll/issue-47388.stderr index a4ee778175306..c780451dfa935 100644 --- a/src/test/ui/nll/issue-47388.stderr +++ b/src/test/ui/nll/issue-47388.stderr @@ -1,10 +1,13 @@ error[E0594]: cannot assign to `fancy_ref.num`, which is behind a `&` reference --> $DIR/issue-47388.rs:8:5 | -LL | let fancy_ref = &(&mut fancy); - | ------------- help: consider changing this to be a mutable reference: `&mut (&mut fancy)` LL | fancy_ref.num = 6; | ^^^^^^^^^^^^^^^^^ `fancy_ref` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | let fancy_ref = &mut (&mut fancy); + | ~~~~~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/nll/issue-51244.stderr b/src/test/ui/nll/issue-51244.stderr index dcb6f9fec18b6..03d8acc81886a 100644 --- a/src/test/ui/nll/issue-51244.stderr +++ b/src/test/ui/nll/issue-51244.stderr @@ -1,10 +1,13 @@ error[E0594]: cannot assign to `*my_ref`, which is behind a `&` reference --> $DIR/issue-51244.rs:3:5 | -LL | let ref my_ref @ _ = 0; - | ---------- help: consider changing this to be a mutable reference: `ref mut my_ref` LL | *my_ref = 0; | ^^^^^^^^^^^ `my_ref` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | let ref mut my_ref @ _ = 0; + | ~~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/nll/issue-57989.stderr b/src/test/ui/nll/issue-57989.stderr index e85e63e52ecc3..31f40d8252ed6 100644 --- a/src/test/ui/nll/issue-57989.stderr +++ b/src/test/ui/nll/issue-57989.stderr @@ -1,11 +1,13 @@ error[E0594]: cannot assign to `*x`, which is behind a `&` reference --> $DIR/issue-57989.rs:5:5 | -LL | fn f(x: &i32) { - | ---- help: consider changing this to be a mutable reference: `&mut i32` -LL | let g = &x; LL | *x = 0; | ^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | fn f(x: &mut i32) { + | ~~~~~~~~ error[E0506]: cannot assign to `*x` because it is borrowed --> $DIR/issue-57989.rs:5:5 diff --git a/src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr b/src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr index bb7b818368b78..1b93267b39771 100644 --- a/src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr +++ b/src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr @@ -104,20 +104,24 @@ LL | *_x0 = U; error[E0594]: cannot assign to `*_x0`, which is behind a `&` reference --> $DIR/borrowck-move-ref-pattern.rs:26:5 | -LL | let (ref _x0, _x1, ref _x2, ..) = tup; - | ------- help: consider changing this to be a mutable reference: `ref mut _x0` -... LL | *_x0 = U; | ^^^^^^^^ `_x0` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | let (ref mut _x0, _x1, ref _x2, ..) = tup; + | ~~~~~~~~~~~ error[E0594]: cannot assign to `*_x2`, which is behind a `&` reference --> $DIR/borrowck-move-ref-pattern.rs:27:5 | -LL | let (ref _x0, _x1, ref _x2, ..) = tup; - | ------- help: consider changing this to be a mutable reference: `ref mut _x2` -... LL | *_x2 = U; | ^^^^^^^^ `_x2` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | let (ref _x0, _x1, ref mut _x2, ..) = tup; + | ~~~~~~~~~~~ error[E0382]: use of moved value: `tup.1` --> $DIR/borrowck-move-ref-pattern.rs:28:10 diff --git a/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr b/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr index e4ec9f875765a..20330c92325e4 100644 --- a/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr +++ b/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr @@ -9,10 +9,13 @@ LL | let __isize = &mut x.y; error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:65:10 | -LL | fn deref_extend_mut_field1(x: &Own) -> &mut isize { - | ----------- help: consider changing this to be a mutable reference: `&mut Own` LL | &mut x.y | ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn deref_extend_mut_field1(x: &mut Own) -> &mut isize { + | ~~~~~~~~~~~~~~~ error[E0499]: cannot borrow `*x` as mutable more than once at a time --> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:78:19 @@ -35,10 +38,13 @@ LL | x.y = 3; error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:92:5 | -LL | fn assign_field2<'a>(x: &'a Own) { - | -------------- help: consider changing this to be a mutable reference: `&'a mut Own` LL | x.y = 3; | ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn assign_field2<'a>(x: &'a mut Own) { + | ~~~~~~~~~~~~~~~~~~ error[E0499]: cannot borrow `*x` as mutable more than once at a time --> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:101:5 @@ -61,10 +67,13 @@ LL | x.set(0, 0); error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:121:5 | -LL | fn deref_extend_mut_method1(x: &Own) -> &mut isize { - | ----------- help: consider changing this to be a mutable reference: `&mut Own` LL | x.y_mut() | ^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn deref_extend_mut_method1(x: &mut Own) -> &mut isize { + | ~~~~~~~~~~~~~~~ error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable --> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:129:6 @@ -77,10 +86,13 @@ LL | *x.y_mut() = 3; error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:133:6 | -LL | fn assign_method2<'a>(x: &'a Own) { - | -------------- help: consider changing this to be a mutable reference: `&'a mut Own` LL | *x.y_mut() = 3; | ^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn assign_method2<'a>(x: &'a mut Own) { + | ~~~~~~~~~~~~~~~~~~ error: aborting due to 10 previous errors diff --git a/src/test/ui/span/borrowck-borrow-overloaded-deref-mut.stderr b/src/test/ui/span/borrowck-borrow-overloaded-deref-mut.stderr index 3ebfba7e4debe..6d34909e43b96 100644 --- a/src/test/ui/span/borrowck-borrow-overloaded-deref-mut.stderr +++ b/src/test/ui/span/borrowck-borrow-overloaded-deref-mut.stderr @@ -9,10 +9,13 @@ LL | let __isize = &mut *x; error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-borrow-overloaded-deref-mut.rs:41:11 | -LL | fn deref_extend_mut1<'a>(x: &'a Own) -> &'a mut isize { - | -------------- help: consider changing this to be a mutable reference: `&'a mut Own` LL | &mut **x | ^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn deref_extend_mut1<'a>(x: &'a mut Own) -> &'a mut isize { + | ~~~~~~~~~~~~~~~~~~ error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable --> $DIR/borrowck-borrow-overloaded-deref-mut.rs:49:6 @@ -25,10 +28,13 @@ LL | *x = 3; error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-borrow-overloaded-deref-mut.rs:53:6 | -LL | fn assign2<'a>(x: &'a Own) { - | -------------- help: consider changing this to be a mutable reference: `&'a mut Own` LL | **x = 3; | ^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn assign2<'a>(x: &'a mut Own) { + | ~~~~~~~~~~~~~~~~~~ error: aborting due to 4 previous errors diff --git a/src/test/ui/span/borrowck-call-is-borrow-issue-12224.stderr b/src/test/ui/span/borrowck-call-is-borrow-issue-12224.stderr index 6b43801b5e074..48b42bc78253f 100644 --- a/src/test/ui/span/borrowck-call-is-borrow-issue-12224.stderr +++ b/src/test/ui/span/borrowck-call-is-borrow-issue-12224.stderr @@ -13,18 +13,24 @@ LL | f((Box::new(|| {}))) error[E0596]: cannot borrow `*f` as mutable, as it is behind a `&` reference --> $DIR/borrowck-call-is-borrow-issue-12224.rs:25:5 | -LL | fn test2(f: &F) where F: FnMut() { - | -- help: consider changing this to be a mutable reference: `&mut F` LL | (*f)(); | ^^^^ `f` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn test2(f: &mut F) where F: FnMut() { + | ~~~~~~ error[E0596]: cannot borrow `f.f` as mutable, as it is behind a `&` reference --> $DIR/borrowck-call-is-borrow-issue-12224.rs:34:5 | -LL | fn test4(f: &Test) { - | ----- help: consider changing this to be a mutable reference: `&mut Test<'_>` LL | f.f.call_mut(()) | ^^^^^^^^^^^^^^^^ `f` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn test4(f: &mut Test<'_>) { + | ~~~~~~~~~~~~~ error[E0507]: cannot move out of `f`, a captured variable in an `FnMut` closure --> $DIR/borrowck-call-is-borrow-issue-12224.rs:57:13 diff --git a/src/test/ui/span/borrowck-call-method-from-mut-aliasable.stderr b/src/test/ui/span/borrowck-call-method-from-mut-aliasable.stderr index 1864f5de108cd..2a842f5a2a9f8 100644 --- a/src/test/ui/span/borrowck-call-method-from-mut-aliasable.stderr +++ b/src/test/ui/span/borrowck-call-method-from-mut-aliasable.stderr @@ -1,11 +1,13 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-call-method-from-mut-aliasable.rs:17:5 | -LL | fn b(x: &Foo) { - | ---- help: consider changing this to be a mutable reference: `&mut Foo` -LL | x.f(); LL | x.h(); | ^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn b(x: &mut Foo) { + | ~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/span/borrowck-fn-in-const-b.stderr b/src/test/ui/span/borrowck-fn-in-const-b.stderr index 1f5d8bd32bb57..1df19deb12f6b 100644 --- a/src/test/ui/span/borrowck-fn-in-const-b.stderr +++ b/src/test/ui/span/borrowck-fn-in-const-b.stderr @@ -1,10 +1,13 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-fn-in-const-b.rs:7:9 | -LL | fn broken(x: &Vec) { - | ------------ help: consider changing this to be a mutable reference: `&mut Vec` LL | x.push(format!("this is broken")); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn broken(x: &mut Vec) { + | ~~~~~~~~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/span/borrowck-object-mutability.stderr b/src/test/ui/span/borrowck-object-mutability.stderr index cc43f6d0928da..e63ca95eff01d 100644 --- a/src/test/ui/span/borrowck-object-mutability.stderr +++ b/src/test/ui/span/borrowck-object-mutability.stderr @@ -1,11 +1,13 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference --> $DIR/borrowck-object-mutability.rs:8:5 | -LL | fn borrowed_receiver(x: &dyn Foo) { - | -------- help: consider changing this to be a mutable reference: `&mut dyn Foo` -LL | x.borrowed(); LL | x.borrowed_mut(); | ^^^^^^^^^^^^^^^^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn borrowed_receiver(x: &mut dyn Foo) { + | ~~~~~~~~~~~~ error[E0596]: cannot borrow `*x` as mutable, as `x` is not declared as mutable --> $DIR/borrowck-object-mutability.rs:18:5 diff --git a/src/test/ui/span/mut-arg-hint.stderr b/src/test/ui/span/mut-arg-hint.stderr index 8a7c504f0053b..96ce4d5bc6c33 100644 --- a/src/test/ui/span/mut-arg-hint.stderr +++ b/src/test/ui/span/mut-arg-hint.stderr @@ -1,26 +1,35 @@ error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference --> $DIR/mut-arg-hint.rs:3:9 | -LL | fn foo(mut a: &String) { - | ------- help: consider changing this to be a mutable reference: `&mut String` LL | a.push_str("bar"); | ^^^^^^^^^^^^^^^^^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn foo(mut a: &mut String) { + | ~~~~~~~~~~~ error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference --> $DIR/mut-arg-hint.rs:8:5 | -LL | pub fn foo<'a>(mut a: &'a String) { - | ---------- help: consider changing this to be a mutable reference: `&'a mut String` LL | a.push_str("foo"); | ^^^^^^^^^^^^^^^^^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | pub fn foo<'a>(mut a: &'a mut String) { + | ~~~~~~~~~~~~~~ error[E0596]: cannot borrow `*a` as mutable, as it is behind a `&` reference --> $DIR/mut-arg-hint.rs:15:9 | -LL | pub fn foo(mut a: &String) { - | ------- help: consider changing this to be a mutable reference: `&mut String` LL | a.push_str("foo"); | ^^^^^^^^^^^^^^^^^ `a` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | pub fn foo(mut a: &mut String) { + | ~~~~~~~~~~~ error: aborting due to 3 previous errors diff --git a/src/test/ui/suggestions/issue-68049-2.stderr b/src/test/ui/suggestions/issue-68049-2.stderr index 2f31193e4a4a2..de35aa5b186b5 100644 --- a/src/test/ui/suggestions/issue-68049-2.stderr +++ b/src/test/ui/suggestions/issue-68049-2.stderr @@ -1,20 +1,24 @@ error[E0594]: cannot assign to `*input`, which is behind a `&` reference --> $DIR/issue-68049-2.rs:9:7 | -LL | fn example(&self, input: &i32); // should suggest here - | ---- help: consider changing that to be a mutable reference: `&mut i32` -... LL | *input = self.0; | ^^^^^^^^^^^^^^^ `input` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing that to be a mutable reference + | +LL | fn example(&self, input: &mut i32); // should suggest here + | ~~~~~~~~ error[E0594]: cannot assign to `self.0`, which is behind a `&` reference --> $DIR/issue-68049-2.rs:17:5 | -LL | fn example(&self, input: &i32); // should suggest here - | ----- help: consider changing that to be a mutable reference: `&mut self` -... LL | self.0 += *input; | ^^^^^^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing that to be a mutable reference + | +LL | fn example(&mut self, input: &i32); // should suggest here + | ~~~~~~~~~ error: aborting due to 2 previous errors diff --git a/src/test/ui/suggestions/suggest-ref-mut.stderr b/src/test/ui/suggestions/suggest-ref-mut.stderr index 9fd2658ec702d..7973759bf5ec7 100644 --- a/src/test/ui/suggestions/suggest-ref-mut.stderr +++ b/src/test/ui/suggestions/suggest-ref-mut.stderr @@ -1,37 +1,46 @@ error[E0594]: cannot assign to `self.0`, which is behind a `&` reference --> $DIR/suggest-ref-mut.rs:7:9 | -LL | fn zap(&self) { - | ----- help: consider changing this to be a mutable reference: `&mut self` -... LL | self.0 = 32; | ^^^^^^^^^^^ `self` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | fn zap(&mut self) { + | ~~~~~~~~~ error[E0594]: cannot assign to `*foo`, which is behind a `&` reference --> $DIR/suggest-ref-mut.rs:16:5 | -LL | let ref foo = 16; - | ------- help: consider changing this to be a mutable reference: `ref mut foo` -... LL | *foo = 32; | ^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | let ref mut foo = 16; + | ~~~~~~~~~~~ error[E0594]: cannot assign to `*bar`, which is behind a `&` reference --> $DIR/suggest-ref-mut.rs:21:9 | -LL | if let Some(ref bar) = Some(16) { - | ------- help: consider changing this to be a mutable reference: `ref mut bar` -... LL | *bar = 32; | ^^^^^^^^^ `bar` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | if let Some(ref mut bar) = Some(16) { + | ~~~~~~~~~~~ error[E0594]: cannot assign to `*quo`, which is behind a `&` reference --> $DIR/suggest-ref-mut.rs:25:22 | LL | ref quo => { *quo = 32; }, - | ------- ^^^^^^^^^ `quo` is a `&` reference, so the data it refers to cannot be written - | | - | help: consider changing this to be a mutable reference: `ref mut quo` + | ^^^^^^^^^ `quo` is a `&` reference, so the data it refers to cannot be written + | +help: consider changing this to be a mutable reference + | +LL | ref mut quo => { *quo = 32; }, + | ~~~~~~~~~~~ error: aborting due to 4 previous errors diff --git a/src/test/ui/trivial-bounds/trivial-bounds-inconsistent-copy-reborrow.stderr b/src/test/ui/trivial-bounds/trivial-bounds-inconsistent-copy-reborrow.stderr index aac119afda544..39b60c3119727 100644 --- a/src/test/ui/trivial-bounds/trivial-bounds-inconsistent-copy-reborrow.stderr +++ b/src/test/ui/trivial-bounds/trivial-bounds-inconsistent-copy-reborrow.stderr @@ -1,18 +1,24 @@ error[E0596]: cannot borrow `**t` as mutable, as it is behind a `&` reference --> $DIR/trivial-bounds-inconsistent-copy-reborrow.rs:6:5 | -LL | fn reborrow_mut<'a>(t: &'a &'a mut i32) -> &'a mut i32 where &'a mut i32: Copy { - | --------------- help: consider changing this to be a mutable reference: `&'a mut &'a mut i32` LL | *t | ^^ `t` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn reborrow_mut<'a>(t: &'a mut &'a mut i32) -> &'a mut i32 where &'a mut i32: Copy { + | ~~~~~~~~~~~~~~~~~~~ error[E0596]: cannot borrow `**t` as mutable, as it is behind a `&` reference --> $DIR/trivial-bounds-inconsistent-copy-reborrow.rs:10:6 | -LL | fn copy_reborrow_mut<'a>(t: &'a &'a mut i32) -> &'a mut i32 where &'a mut i32: Copy { - | --------------- help: consider changing this to be a mutable reference: `&'a mut &'a mut i32` LL | {*t} | ^^ `t` is a `&` reference, so the data it refers to cannot be borrowed as mutable + | +help: consider changing this to be a mutable reference + | +LL | fn copy_reborrow_mut<'a>(t: &'a mut &'a mut i32) -> &'a mut i32 where &'a mut i32: Copy { + | ~~~~~~~~~~~~~~~~~~~ error: aborting due to 2 previous errors