Skip to content

tweak "make mut" spans when assigning to locals #110583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
509 changes: 264 additions & 245 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/ui/array-slice-vec/slice-mut-2.stderr
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ LL | let _ = &mut x[2..4];
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

Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ LL | let q = &raw mut *x;
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
@@ -18,7 +18,7 @@ LL | let q = &raw mut *x;
help: consider changing this to be a mutable pointer
|
LL | let x = &mut 0 as *const i32;
| ~~~~~~
| +++

error: aborting due to 2 previous errors

6 changes: 3 additions & 3 deletions tests/ui/borrowck/borrowck-access-permissions.stderr
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ LL | let _y1 = &mut *ref_x;
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
@@ -46,7 +46,7 @@ LL | let _y1 = &mut *ptr_x;
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
@@ -57,7 +57,7 @@ LL | let _y = &mut *foo_ref.f;
help: consider changing this to be a mutable reference
|
LL | let foo_ref = &mut foo;
| ~~~~~~~~
| +++

error: aborting due to 6 previous errors

Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ LL | *s.pointer += 1;
|
help: consider changing this to be a mutable reference
|
LL | fn a(s: &mut S<'_>) {
| ~~~~~~~~~~
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
@@ -17,8 +17,8 @@ LL | *s.pointer += 1;
|
help: consider changing this to be a mutable reference
|
LL | fn c(s: &mut &mut S<'_>) {
| ~~~~~~~~~~~~~~~
LL | fn c(s: &mut &mut S) {
| +++

error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
@@ -27,8 +27,8 @@ LL | let x: &mut isize = &mut **t0;
|
help: consider changing this to be a mutable reference
|
LL | fn foo4(t0: &mut &mut isize) {
| ~~~~~~~~~~~~~~~
LL | fn foo4(t0: &mut &mut isize) {
| +++

error: aborting due to 3 previous errors

2 changes: 1 addition & 1 deletion tests/ui/borrowck/borrowck-issue-14498.stderr
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ LL | ***p = 2;
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
2 changes: 1 addition & 1 deletion tests/ui/borrowck/borrowck-reborrow-from-mut.stderr
Original file line number Diff line number Diff line change
@@ -111,7 +111,7 @@ LL | let _bar1 = &mut foo.bar1;
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

2 changes: 1 addition & 1 deletion tests/ui/borrowck/issue-85765.stderr
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ LL | *r = 0;
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
24 changes: 12 additions & 12 deletions tests/ui/borrowck/mutability-errors.stderr
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ LL | *x = (1,);
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
@@ -18,7 +18,7 @@ LL | x.0 = 1;
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
@@ -29,7 +29,7 @@ LL | &mut *x;
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
@@ -40,7 +40,7 @@ LL | &mut x.0;
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
@@ -74,8 +74,8 @@ LL | *x = (1,);
|
help: consider changing this to be a mutable pointer
|
LL | unsafe fn named_ptr(x: *mut (i32,)) {
| ~~~~~~~~~~~
LL | unsafe fn named_ptr(x: *mut const (i32,)) {
| +++

error[E0594]: cannot assign to `x.0`, which is behind a `*const` pointer
--> $DIR/mutability-errors.rs:24:5
@@ -85,8 +85,8 @@ LL | (*x).0 = 1;
|
help: consider changing this to be a mutable pointer
|
LL | unsafe fn named_ptr(x: *mut (i32,)) {
| ~~~~~~~~~~~
LL | unsafe fn named_ptr(x: *mut const (i32,)) {
| +++

error[E0596]: cannot borrow `*x` as mutable, as it is behind a `*const` pointer
--> $DIR/mutability-errors.rs:25:5
@@ -96,8 +96,8 @@ LL | &mut *x;
|
help: consider changing this to be a mutable pointer
|
LL | unsafe fn named_ptr(x: *mut (i32,)) {
| ~~~~~~~~~~~
LL | unsafe fn named_ptr(x: *mut const (i32,)) {
| +++

error[E0596]: cannot borrow `x.0` as mutable, as it is behind a `*const` pointer
--> $DIR/mutability-errors.rs:26:5
@@ -107,8 +107,8 @@ LL | &mut (*x).0;
|
help: consider changing this to be a mutable pointer
|
LL | unsafe fn named_ptr(x: *mut (i32,)) {
| ~~~~~~~~~~~
LL | unsafe fn named_ptr(x: *mut const (i32,)) {
| +++

error[E0594]: cannot assign to data in a `*const` pointer
--> $DIR/mutability-errors.rs:30:5
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ LL | **ref_mref_x = y;
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
4 changes: 2 additions & 2 deletions tests/ui/did_you_mean/issue-38147-4.stderr
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ LL | f.s.push('x');
|
help: consider changing this to be a mutable reference
|
LL | fn f(x: usize, f: &mut Foo<'_>) {
| ~~~~~~~~~~~~
LL | fn f(x: usize, f: &mut Foo) {
| +++

error: aborting due to previous error

12 changes: 6 additions & 6 deletions tests/ui/did_you_mean/issue-39544.stderr
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ LL | let _ = &mut other.x;
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
@@ -62,7 +62,7 @@ LL | let _ = &mut other.x;
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
@@ -73,7 +73,7 @@ LL | let _ = &mut self.x;
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
@@ -84,7 +84,7 @@ LL | let _ = &mut other.x;
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
@@ -95,7 +95,7 @@ LL | let _ = &mut other.x;
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
@@ -117,7 +117,7 @@ LL | let _ = &mut w.x;
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
2 changes: 1 addition & 1 deletion tests/ui/did_you_mean/issue-40823.stderr
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ LL | buf.iter_mut();
help: consider changing this to be a mutable reference
|
LL | let mut buf = &mut [1, 2, 3, 4];
| ~~~~~~~~~~~~~~~~~
| +++

error: aborting due to previous error

2 changes: 1 addition & 1 deletion tests/ui/error-codes/E0389.stderr
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ LL | fancy_ref.num = 6;
help: consider changing this to be a mutable reference
|
LL | let fancy_ref = &mut (&mut fancy);
| ~~~~~~~~~~~~~~~~~
| +++

error: aborting due to previous error

1 change: 0 additions & 1 deletion tests/ui/issues/issue-51515.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
fn main() {
let foo = &16;
//~^ HELP consider changing this to be a mutable reference
//~| SUGGESTION &mut 16
*foo = 32;
//~^ ERROR cannot assign to `*foo`, which is behind a `&` reference
let bar = foo;
6 changes: 3 additions & 3 deletions tests/ui/issues/issue-51515.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
error[E0594]: cannot assign to `*foo`, which is behind a `&` reference
--> $DIR/issue-51515.rs:5:5
--> $DIR/issue-51515.rs:4:5
|
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:9:5
--> $DIR/issue-51515.rs:8:5
|
LL | *bar = 64;
| ^^^^^^^^^ `bar` is a `&` reference, so the data it refers to cannot be written
2 changes: 1 addition & 1 deletion tests/ui/issues/issue-61623.stderr
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ LL | f2(|| x.0, f1(x.1))
help: consider changing this to be a mutable reference
|
LL | fn f3<'a>(x: &'a mut ((), &'a mut ())) {
| ~~~~~~~~~~~~~~~~~~~~~~~~
| +++

error: aborting due to previous error

2 changes: 1 addition & 1 deletion tests/ui/nll/issue-47388.stderr
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ LL | fancy_ref.num = 6;
help: consider changing this to be a mutable reference
|
LL | let fancy_ref = &mut (&mut fancy);
| ~~~~~~~~~~~~~~~~~
| +++

error: aborting due to previous error

2 changes: 1 addition & 1 deletion tests/ui/nll/issue-51244.stderr
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ LL | *my_ref = 0;
help: consider changing this to be a mutable reference
|
LL | let ref mut my_ref @ _ = 0;
| ~~~~~~~~~~~~~~
| +++

error: aborting due to previous error

2 changes: 1 addition & 1 deletion tests/ui/nll/issue-57989.stderr
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ LL | *x = 0;
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
Original file line number Diff line number Diff line change
@@ -112,7 +112,7 @@ LL | *_x0 = U;
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
@@ -123,7 +123,7 @@ LL | *_x2 = U;
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
Loading