Skip to content

Commit ff30b8c

Browse files
authored
Rollup merge of #110583 - Ezrashaw:tweak-make-mut-spans, r=estebank
tweak "make mut" spans when assigning to locals Work towards fixing #106857 This PR just cleans up a lot of spans which is helpful before properly fixing the issues. Best reviewed commit-by-commit. r? `@estebank`
2 parents 2ecc722 + 3e64e98 commit ff30b8c

33 files changed

+338
-323
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+264-245
Large diffs are not rendered by default.

tests/ui/array-slice-vec/slice-mut-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let _ = &mut x[2..4];
77
help: consider changing this to be a mutable reference
88
|
99
LL | let x: &[isize] = &mut [1, 2, 3, 4, 5];
10-
| ~~~~~~~~~~~~~~~~~~~~
10+
| +++
1111

1212
error: aborting due to previous error
1313

tests/ui/borrowck/borrow-raw-address-of-deref-mutability.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let q = &raw mut *x;
77
help: consider changing this to be a mutable reference
88
|
99
LL | let x = &mut 0;
10-
| ~~~~~~
10+
| +++
1111

1212
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `*const` pointer
1313
--> $DIR/borrow-raw-address-of-deref-mutability.rs:14:13
@@ -18,7 +18,7 @@ LL | let q = &raw mut *x;
1818
help: consider changing this to be a mutable pointer
1919
|
2020
LL | let x = &mut 0 as *const i32;
21-
| ~~~~~~
21+
| +++
2222

2323
error: aborting due to 2 previous errors
2424

tests/ui/borrowck/borrowck-access-permissions.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ LL | let _y1 = &mut *ref_x;
3535
help: consider changing this to be a mutable reference
3636
|
3737
LL | let ref_x = &mut x;
38-
| ~~~~~~
38+
| +++
3939

4040
error[E0596]: cannot borrow `*ptr_x` as mutable, as it is behind a `*const` pointer
4141
--> $DIR/borrowck-access-permissions.rs:39:23
@@ -46,7 +46,7 @@ LL | let _y1 = &mut *ptr_x;
4646
help: consider changing this to be a mutable pointer
4747
|
4848
LL | let ptr_x : *const _ = &mut x;
49-
| ~~~~~~
49+
| +++
5050

5151
error[E0596]: cannot borrow `*foo_ref.f` as mutable, as it is behind a `&` reference
5252
--> $DIR/borrowck-access-permissions.rs:48:18
@@ -57,7 +57,7 @@ LL | let _y = &mut *foo_ref.f;
5757
help: consider changing this to be a mutable reference
5858
|
5959
LL | let foo_ref = &mut foo;
60-
| ~~~~~~~~
60+
| +++
6161

6262
error: aborting due to 6 previous errors
6363

tests/ui/borrowck/borrowck-assign-to-andmut-in-aliasable-loc.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | *s.pointer += 1;
66
|
77
help: consider changing this to be a mutable reference
88
|
9-
LL | fn a(s: &mut S<'_>) {
10-
| ~~~~~~~~~~
9+
LL | fn a(s: &mut S) {
10+
| +++
1111

1212
error[E0594]: cannot assign to `*s.pointer`, which is behind a `&` reference
1313
--> $DIR/borrowck-assign-to-andmut-in-aliasable-loc.rs:17:5
@@ -17,8 +17,8 @@ LL | *s.pointer += 1;
1717
|
1818
help: consider changing this to be a mutable reference
1919
|
20-
LL | fn c(s: &mut &mut S<'_>) {
21-
| ~~~~~~~~~~~~~~~
20+
LL | fn c(s: &mut &mut S) {
21+
| +++
2222

2323
error: aborting due to 2 previous errors
2424

tests/ui/borrowck/borrowck-borrow-mut-base-ptr-in-aliasable-loc.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ LL | let x: &mut isize = &mut **t0;
2727
|
2828
help: consider changing this to be a mutable reference
2929
|
30-
LL | fn foo4(t0: &mut &mut isize) {
31-
| ~~~~~~~~~~~~~~~
30+
LL | fn foo4(t0: &mut &mut isize) {
31+
| +++
3232

3333
error: aborting due to 3 previous errors
3434

tests/ui/borrowck/borrowck-issue-14498.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | ***p = 2;
77
help: consider changing this to be a mutable reference
88
|
99
LL | let p = &mut y;
10-
| ~~~~~~
10+
| +++
1111

1212
error[E0506]: cannot assign to `**y` because it is borrowed
1313
--> $DIR/borrowck-issue-14498.rs:25:5

tests/ui/borrowck/borrowck-reborrow-from-mut.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ LL | let _bar1 = &mut foo.bar1;
111111
help: consider changing this to be a mutable reference
112112
|
113113
LL | fn borrow_mut_from_imm(foo: &mut Foo) {
114-
| ~~~~~~~~
114+
| +++
115115

116116
error: aborting due to 11 previous errors
117117

tests/ui/borrowck/issue-85765.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LL | *r = 0;
1818
help: consider changing this to be a mutable reference
1919
|
2020
LL | let r = &mut mutvar;
21-
| ~~~~~~~~~~~
21+
| +++
2222

2323
error[E0594]: cannot assign to `*x`, which is behind a `&` reference
2424
--> $DIR/issue-85765.rs:19:5

tests/ui/borrowck/mutability-errors.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | *x = (1,);
77
help: consider changing this to be a mutable reference
88
|
99
LL | fn named_ref(x: &mut (i32,)) {
10-
| ~~~~~~~~~~~
10+
| +++
1111

1212
error[E0594]: cannot assign to `x.0`, which is behind a `&` reference
1313
--> $DIR/mutability-errors.rs:10:5
@@ -18,7 +18,7 @@ LL | x.0 = 1;
1818
help: consider changing this to be a mutable reference
1919
|
2020
LL | fn named_ref(x: &mut (i32,)) {
21-
| ~~~~~~~~~~~
21+
| +++
2222

2323
error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
2424
--> $DIR/mutability-errors.rs:11:5
@@ -29,7 +29,7 @@ LL | &mut *x;
2929
help: consider changing this to be a mutable reference
3030
|
3131
LL | fn named_ref(x: &mut (i32,)) {
32-
| ~~~~~~~~~~~
32+
| +++
3333

3434
error[E0596]: cannot borrow `x.0` as mutable, as it is behind a `&` reference
3535
--> $DIR/mutability-errors.rs:12:5
@@ -40,7 +40,7 @@ LL | &mut x.0;
4040
help: consider changing this to be a mutable reference
4141
|
4242
LL | fn named_ref(x: &mut (i32,)) {
43-
| ~~~~~~~~~~~
43+
| +++
4444

4545
error[E0594]: cannot assign to data in a `&` reference
4646
--> $DIR/mutability-errors.rs:16:5
@@ -74,8 +74,8 @@ LL | *x = (1,);
7474
|
7575
help: consider changing this to be a mutable pointer
7676
|
77-
LL | unsafe fn named_ptr(x: *mut (i32,)) {
78-
| ~~~~~~~~~~~
77+
LL | unsafe fn named_ptr(x: *mut const (i32,)) {
78+
| +++
7979

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

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

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

113113
error[E0594]: cannot assign to data in a `*const` pointer
114114
--> $DIR/mutability-errors.rs:30:5

tests/ui/closures/2229_closure_analysis/diagnostics/mut_ref.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LL | **ref_mref_x = y;
1010
help: consider changing this to be a mutable reference
1111
|
1212
LL | let ref_mref_x = &mut mref_x;
13-
| ~~~~~~~~~~~
13+
| +++
1414

1515
error[E0596]: cannot borrow `**mref_ref_x` as mutable, as it is behind a `&` reference
1616
--> $DIR/mut_ref.rs:26:13

tests/ui/did_you_mean/issue-38147-4.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ LL | f.s.push('x');
66
|
77
help: consider changing this to be a mutable reference
88
|
9-
LL | fn f(x: usize, f: &mut Foo<'_>) {
10-
| ~~~~~~~~~~~~
9+
LL | fn f(x: usize, f: &mut Foo) {
10+
| +++
1111

1212
error: aborting due to previous error
1313

tests/ui/did_you_mean/issue-39544.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ LL | let _ = &mut other.x;
4040
help: consider changing this to be a mutable reference
4141
|
4242
LL | fn foo1(&self, other: &mut Z) {
43-
| ~~~~~~
43+
| +++
4444

4545
error[E0596]: cannot borrow `self.x` as mutable, as it is behind a `&` reference
4646
--> $DIR/issue-39544.rs:25:17
@@ -62,7 +62,7 @@ LL | let _ = &mut other.x;
6262
help: consider changing this to be a mutable reference
6363
|
6464
LL | fn foo2<'a>(&'a self, other: &mut Z) {
65-
| ~~~~~~
65+
| +++
6666

6767
error[E0596]: cannot borrow `self.x` as mutable, as it is behind a `&` reference
6868
--> $DIR/issue-39544.rs:30:17
@@ -73,7 +73,7 @@ LL | let _ = &mut self.x;
7373
help: consider changing this to be a mutable reference
7474
|
7575
LL | fn foo3<'a>(self: &'a mut Self, other: &Z) {
76-
| ~~~~~~~~~~~~
76+
| +++
7777

7878
error[E0596]: cannot borrow `other.x` as mutable, as it is behind a `&` reference
7979
--> $DIR/issue-39544.rs:31:17
@@ -84,7 +84,7 @@ LL | let _ = &mut other.x;
8484
help: consider changing this to be a mutable reference
8585
|
8686
LL | fn foo3<'a>(self: &'a Self, other: &mut Z) {
87-
| ~~~~~~
87+
| +++
8888

8989
error[E0596]: cannot borrow `other.x` as mutable, as it is behind a `&` reference
9090
--> $DIR/issue-39544.rs:35:17
@@ -95,7 +95,7 @@ LL | let _ = &mut other.x;
9595
help: consider changing this to be a mutable reference
9696
|
9797
LL | fn foo4(other: &mut Z) {
98-
| ~~~~~~
98+
| +++
9999

100100
error[E0596]: cannot borrow `z.x` as mutable, as `z` is not declared as mutable
101101
--> $DIR/issue-39544.rs:41:13
@@ -117,7 +117,7 @@ LL | let _ = &mut w.x;
117117
help: consider changing this to be a mutable reference
118118
|
119119
LL | pub fn with_arg(z: Z, w: &mut Z) {
120-
| ~~~~~~
120+
| +++
121121

122122
error[E0594]: cannot assign to `*x.0`, which is behind a `&` reference
123123
--> $DIR/issue-39544.rs:48:5

tests/ui/did_you_mean/issue-40823.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | buf.iter_mut();
77
help: consider changing this to be a mutable reference
88
|
99
LL | let mut buf = &mut [1, 2, 3, 4];
10-
| ~~~~~~~~~~~~~~~~~
10+
| +++
1111

1212
error: aborting due to previous error
1313

tests/ui/error-codes/E0389.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | fancy_ref.num = 6;
77
help: consider changing this to be a mutable reference
88
|
99
LL | let fancy_ref = &mut (&mut fancy);
10-
| ~~~~~~~~~~~~~~~~~
10+
| +++
1111

1212
error: aborting due to previous error
1313

tests/ui/issues/issue-51515.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
fn main() {
22
let foo = &16;
33
//~^ HELP consider changing this to be a mutable reference
4-
//~| SUGGESTION &mut 16
54
*foo = 32;
65
//~^ ERROR cannot assign to `*foo`, which is behind a `&` reference
76
let bar = foo;

tests/ui/issues/issue-51515.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
error[E0594]: cannot assign to `*foo`, which is behind a `&` reference
2-
--> $DIR/issue-51515.rs:5:5
2+
--> $DIR/issue-51515.rs:4:5
33
|
44
LL | *foo = 32;
55
| ^^^^^^^^^ `foo` is a `&` reference, so the data it refers to cannot be written
66
|
77
help: consider changing this to be a mutable reference
88
|
99
LL | let foo = &mut 16;
10-
| ~~~~~~~
10+
| +++
1111

1212
error[E0594]: cannot assign to `*bar`, which is behind a `&` reference
13-
--> $DIR/issue-51515.rs:9:5
13+
--> $DIR/issue-51515.rs:8:5
1414
|
1515
LL | *bar = 64;
1616
| ^^^^^^^^^ `bar` is a `&` reference, so the data it refers to cannot be written

tests/ui/issues/issue-61623.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | f2(|| x.0, f1(x.1))
77
help: consider changing this to be a mutable reference
88
|
99
LL | fn f3<'a>(x: &'a mut ((), &'a mut ())) {
10-
| ~~~~~~~~~~~~~~~~~~~~~~~~
10+
| +++
1111

1212
error: aborting due to previous error
1313

tests/ui/nll/issue-47388.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | fancy_ref.num = 6;
77
help: consider changing this to be a mutable reference
88
|
99
LL | let fancy_ref = &mut (&mut fancy);
10-
| ~~~~~~~~~~~~~~~~~
10+
| +++
1111

1212
error: aborting due to previous error
1313

tests/ui/nll/issue-51244.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | *my_ref = 0;
77
help: consider changing this to be a mutable reference
88
|
99
LL | let ref mut my_ref @ _ = 0;
10-
| ~~~~~~~~~~~~~~
10+
| +++
1111

1212
error: aborting due to previous error
1313

tests/ui/nll/issue-57989.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | *x = 0;
77
help: consider changing this to be a mutable reference
88
|
99
LL | fn f(x: &mut i32) {
10-
| ~~~~~~~~
10+
| +++
1111

1212
error[E0506]: cannot assign to `*x` because it is borrowed
1313
--> $DIR/issue-57989.rs:5:5

tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ LL | *_x0 = U;
112112
help: consider changing this to be a mutable reference
113113
|
114114
LL | let (ref mut _x0, _x1, ref _x2, ..) = tup;
115-
| ~~~~~~~~~~~
115+
| +++
116116

117117
error[E0594]: cannot assign to `*_x2`, which is behind a `&` reference
118118
--> $DIR/borrowck-move-ref-pattern.rs:27:5
@@ -123,7 +123,7 @@ LL | *_x2 = U;
123123
help: consider changing this to be a mutable reference
124124
|
125125
LL | let (ref _x0, _x1, ref mut _x2, ..) = tup;
126-
| ~~~~~~~~~~~
126+
| +++
127127

128128
error[E0382]: use of moved value: `tup.1`
129129
--> $DIR/borrowck-move-ref-pattern.rs:28:10

0 commit comments

Comments
 (0)