Use verbose suggestions for mutability errors

This commit is contained in:
Esteban Küber 2022-12-28 21:52:57 -08:00
parent 92c1937a90
commit b9439ebf12
34 changed files with 338 additions and 181 deletions

View File

@ -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}"));
}
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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<Point>) -> &mut isize {
| ----------- help: consider changing this to be a mutable reference: `&mut Own<Point>`
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<Point>) -> &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<Point>) {
| -------------- help: consider changing this to be a mutable reference: `&'a mut Own<Point>`
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<Point>) {
| ~~~~~~~~~~~~~~~~~~
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<Point>) -> &mut isize {
| ----------- help: consider changing this to be a mutable reference: `&mut Own<Point>`
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<Point>) -> &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<Point>) {
| -------------- help: consider changing this to be a mutable reference: `&'a mut Own<Point>`
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<Point>) {
| ~~~~~~~~~~~~~~~~~~
error: aborting due to 10 previous errors

View File

@ -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<isize>) -> &'a mut isize {
| -------------- help: consider changing this to be a mutable reference: `&'a mut Own<isize>`
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<isize>) -> &'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<isize>) {
| -------------- help: consider changing this to be a mutable reference: `&'a mut Own<isize>`
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<isize>) {
| ~~~~~~~~~~~~~~~~~~
error: aborting due to 4 previous errors

View File

@ -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: &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>(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

View File

@ -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

View File

@ -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<String>) {
| ------------ help: consider changing this to be a mutable reference: `&mut Vec<String>`
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<String>) {
| ~~~~~~~~~~~~~~~~
error: aborting due to previous error

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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