Skip to content

Commit 5454065

Browse files
committed
Verbose suggestions
1 parent 5bfcfee commit 5454065

File tree

53 files changed

+363
-188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+363
-188
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
377377
err.span_label(span, format!("cannot {act}"));
378378
}
379379
if suggest {
380-
err.span_suggestion(
381-
local_decl.source_info.span,
380+
err.span_suggestion_verbose(
381+
local_decl.source_info.span.shrink_to_lo(),
382382
"consider changing this to be mutable",
383-
format!("mut {}", self.local_names[local].unwrap()),
383+
"mut ".to_string(),
384384
Applicability::MachineApplicable,
385385
);
386386
let tcx = self.infcx.tcx;

src/test/ui/asm/aarch64/type-check-2-2.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@ fn main() {
2525

2626
// Outputs require mutable places
2727

28-
let v: Vec<u64> = vec![0, 1, 2];
28+
let v: Vec<u64> = vec![0, 1, 2]; //~ ERROR cannot borrow `v` as mutable
2929
asm!("{}", in(reg) v[0]);
3030
asm!("{}", out(reg) v[0]);
31-
//~^ ERROR cannot borrow `v` as mutable, as it is not declared as mutable
3231
asm!("{}", inout(reg) v[0]);
33-
//~^ ERROR cannot borrow `v` as mutable, as it is not declared as mutable
3432

3533
// Sym operands must point to a function or static
3634
}

src/test/ui/asm/aarch64/type-check-2-2.stderr

+10-12
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,22 @@ LL | let mut y: u64 = 0;
2525
| +++
2626

2727
error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable
28-
--> $DIR/type-check-2-2.rs:30:29
28+
--> $DIR/type-check-2-2.rs:28:13
2929
|
3030
LL | let v: Vec<u64> = vec![0, 1, 2];
31-
| - help: consider changing this to be mutable: `mut v`
31+
| ^ not mutable
3232
LL | asm!("{}", in(reg) v[0]);
3333
LL | asm!("{}", out(reg) v[0]);
34-
| ^ cannot borrow as mutable
35-
36-
error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable
37-
--> $DIR/type-check-2-2.rs:32:31
38-
|
39-
LL | let v: Vec<u64> = vec![0, 1, 2];
40-
| - help: consider changing this to be mutable: `mut v`
41-
...
34+
| - cannot borrow as mutable
4235
LL | asm!("{}", inout(reg) v[0]);
43-
| ^ cannot borrow as mutable
36+
| - cannot borrow as mutable
37+
|
38+
help: consider changing this to be mutable
39+
|
40+
LL | let mut v: Vec<u64> = vec![0, 1, 2];
41+
| +++
4442

45-
error: aborting due to 4 previous errors
43+
error: aborting due to 3 previous errors
4644

4745
Some errors have detailed explanations: E0381, E0596.
4846
For more information about an error, try `rustc --explain E0381`.

src/test/ui/asm/x86_64/type-check-5.stderr

+6-4
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable
2828
--> $DIR/type-check-5.rs:24:13
2929
|
3030
LL | let v: Vec<u64> = vec![0, 1, 2];
31-
| ^
32-
| |
33-
| not mutable
34-
| help: consider changing this to be mutable: `mut v`
31+
| ^ not mutable
3532
...
3633
LL | asm!("{}", out(reg) v[0]);
3734
| - cannot borrow as mutable
3835
LL | asm!("{}", inout(reg) v[0]);
3936
| - cannot borrow as mutable
37+
|
38+
help: consider changing this to be mutable
39+
|
40+
LL | let mut v: Vec<u64> = vec![0, 1, 2];
41+
| +++
4042

4143
error: aborting due to 3 previous errors
4244

src/test/ui/async-await/issue-61452.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
22
--> $DIR/issue-61452.rs:4:5
33
|
4-
LL | pub async fn f(x: Option<usize>) {
5-
| - help: consider changing this to be mutable: `mut x`
64
LL | x.take();
75
| ^^^^^^^^ cannot borrow as mutable
6+
|
7+
help: consider changing this to be mutable
8+
|
9+
LL | pub async fn f(mut x: Option<usize>) {
10+
| +++
811

912
error[E0384]: cannot assign twice to immutable variable `x`
1013
--> $DIR/issue-61452.rs:9:5

src/test/ui/async-await/issues/issue-61187.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0596]: cannot borrow `data` as mutable, as it is not declared as mutable
22
--> $DIR/issue-61187.rs:6:5
33
|
4-
LL | async fn response(data: Vec<u8>) {
5-
| ---- help: consider changing this to be mutable: `mut data`
64
LL | data.reverse();
75
| ^^^^^^^^^^^^^^ cannot borrow as mutable
6+
|
7+
help: consider changing this to be mutable
8+
|
9+
LL | async fn response(mut data: Vec<u8>) {
10+
| +++
811

912
error: aborting due to previous error
1013

src/test/ui/augmented-assignments.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main() {
1919

2020
let y = Int(2);
2121
//~^ HELP consider changing this to be mutable
22-
//~| SUGGESTION mut y
22+
//~| SUGGESTION mut
2323
y //~ ERROR cannot borrow `y` as mutable, as it is not declared as mutable
2424
//~| cannot borrow as mutable
2525
+=

src/test/ui/augmented-assignments.stderr

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ LL | x;
1010
error[E0596]: cannot borrow `y` as mutable, as it is not declared as mutable
1111
--> $DIR/augmented-assignments.rs:23:5
1212
|
13-
LL | let y = Int(2);
14-
| - help: consider changing this to be mutable: `mut y`
15-
...
1613
LL | y
1714
| ^ cannot borrow as mutable
15+
|
16+
help: consider changing this to be mutable
17+
|
18+
LL | let mut y = Int(2);
19+
| +++
1820

1921
error: aborting due to 2 previous errors
2022

src/test/ui/borrowck/borrow-raw-address-of-mutability.stderr

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
22
--> $DIR/borrow-raw-address-of-mutability.rs:5:13
33
|
4-
LL | let x = 0;
5-
| - help: consider changing this to be mutable: `mut x`
64
LL | let y = &raw mut x;
75
| ^^^^^^^^^^ cannot borrow as mutable
6+
|
7+
help: consider changing this to be mutable
8+
|
9+
LL | let mut x = 0;
10+
| +++
811

912
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
1013
--> $DIR/borrow-raw-address-of-mutability.rs:11:17
@@ -18,13 +21,16 @@ LL | let y = &raw mut x;
1821
error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable
1922
--> $DIR/borrow-raw-address-of-mutability.rs:21:5
2023
|
21-
LL | let f = || {
22-
| - help: consider changing this to be mutable: `mut f`
2324
LL | let y = &raw mut x;
2425
| - calling `f` requires mutable binding due to mutable borrow of `x`
2526
LL | };
2627
LL | f();
2728
| ^ cannot borrow as mutable
29+
|
30+
help: consider changing this to be mutable
31+
|
32+
LL | let mut f = || {
33+
| +++
2834

2935
error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure
3036
--> $DIR/borrow-raw-address-of-mutability.rs:29:17

src/test/ui/borrowck/borrowck-access-permissions.stderr

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
22
--> $DIR/borrowck-access-permissions.rs:9:19
33
|
4-
LL | let x = 1;
5-
| - help: consider changing this to be mutable: `mut x`
6-
...
74
LL | let _y1 = &mut x;
85
| ^^^^^^ cannot borrow as mutable
6+
|
7+
help: consider changing this to be mutable
8+
|
9+
LL | let mut x = 1;
10+
| +++
911

1012
error[E0596]: cannot borrow immutable static item `static_x` as mutable
1113
--> $DIR/borrowck-access-permissions.rs:14:19
@@ -16,11 +18,13 @@ LL | let _y1 = &mut static_x;
1618
error[E0596]: cannot borrow `*box_x` as mutable, as `box_x` is not declared as mutable
1719
--> $DIR/borrowck-access-permissions.rs:22:19
1820
|
19-
LL | let box_x = Box::new(1);
20-
| ----- help: consider changing this to be mutable: `mut box_x`
21-
...
2221
LL | let _y1 = &mut *box_x;
2322
| ^^^^^^^^^^^ cannot borrow as mutable
23+
|
24+
help: consider changing this to be mutable
25+
|
26+
LL | let mut box_x = Box::new(1);
27+
| +++
2428

2529
error[E0596]: cannot borrow `*ref_x` as mutable, as it is behind a `&` reference
2630
--> $DIR/borrowck-access-permissions.rs:30:19

src/test/ui/borrowck/borrowck-argument.stderr

+21-9
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,46 @@
11
error[E0596]: cannot borrow `arg` as mutable, as it is not declared as mutable
22
--> $DIR/borrowck-argument.rs:10:5
33
|
4-
LL | fn func(arg: S) {
5-
| --- help: consider changing this to be mutable: `mut arg`
64
LL | arg.mutate();
75
| ^^^^^^^^^^^^ cannot borrow as mutable
6+
|
7+
help: consider changing this to be mutable
8+
|
9+
LL | fn func(mut arg: S) {
10+
| +++
811

912
error[E0596]: cannot borrow `arg` as mutable, as it is not declared as mutable
1013
--> $DIR/borrowck-argument.rs:15:9
1114
|
12-
LL | fn method(&self, arg: S) {
13-
| --- help: consider changing this to be mutable: `mut arg`
1415
LL | arg.mutate();
1516
| ^^^^^^^^^^^^ cannot borrow as mutable
17+
|
18+
help: consider changing this to be mutable
19+
|
20+
LL | fn method(&self, mut arg: S) {
21+
| +++
1622

1723
error[E0596]: cannot borrow `arg` as mutable, as it is not declared as mutable
1824
--> $DIR/borrowck-argument.rs:21:9
1925
|
20-
LL | fn default(&self, arg: S) {
21-
| --- help: consider changing this to be mutable: `mut arg`
2226
LL | arg.mutate();
2327
| ^^^^^^^^^^^^ cannot borrow as mutable
28+
|
29+
help: consider changing this to be mutable
30+
|
31+
LL | fn default(&self, mut arg: S) {
32+
| +++
2433

2534
error[E0596]: cannot borrow `arg` as mutable, as it is not declared as mutable
2635
--> $DIR/borrowck-argument.rs:32:17
2736
|
2837
LL | (|arg: S| { arg.mutate() })(s);
29-
| --- ^^^^^^^^^^^^ cannot borrow as mutable
30-
| |
31-
| help: consider changing this to be mutable: `mut arg`
38+
| ^^^^^^^^^^^^ cannot borrow as mutable
39+
|
40+
help: consider changing this to be mutable
41+
|
42+
LL | (|mut arg: S| { arg.mutate() })(s);
43+
| +++
3244

3345
error: aborting due to 4 previous errors
3446

src/test/ui/borrowck/borrowck-auto-mut-ref-to-immut-var.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
22
--> $DIR/borrowck-auto-mut-ref-to-immut-var.rs:15:5
33
|
4-
LL | let x = Foo { x: 3 };
5-
| - help: consider changing this to be mutable: `mut x`
64
LL | x.printme();
75
| ^^^^^^^^^^^ cannot borrow as mutable
6+
|
7+
help: consider changing this to be mutable
8+
|
9+
LL | let mut x = Foo { x: 3 };
10+
| +++
811

912
error: aborting due to previous error
1013

src/test/ui/borrowck/borrowck-borrow-from-owned-ptr.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,13 @@ LL | *bar1;
105105
error[E0596]: cannot borrow `foo.bar1` as mutable, as `foo` is not declared as mutable
106106
--> $DIR/borrowck-borrow-from-owned-ptr.rs:122:16
107107
|
108-
LL | let foo = make_foo();
109-
| --- help: consider changing this to be mutable: `mut foo`
110108
LL | let bar1 = &mut foo.bar1;
111109
| ^^^^^^^^^^^^^ cannot borrow as mutable
110+
|
111+
help: consider changing this to be mutable
112+
|
113+
LL | let mut foo = make_foo();
114+
| +++
112115

113116
error: aborting due to 11 previous errors
114117

src/test/ui/borrowck/borrowck-borrow-from-stack-variable.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,13 @@ LL | *bar1;
105105
error[E0596]: cannot borrow `foo.bar1` as mutable, as `foo` is not declared as mutable
106106
--> $DIR/borrowck-borrow-from-stack-variable.rs:120:16
107107
|
108-
LL | let foo = make_foo();
109-
| --- help: consider changing this to be mutable: `mut foo`
110108
LL | let bar1 = &mut foo.bar1;
111109
| ^^^^^^^^^^^^^ cannot borrow as mutable
110+
|
111+
help: consider changing this to be mutable
112+
|
113+
LL | let mut foo = make_foo();
114+
| +++
112115

113116
error: aborting due to 11 previous errors
114117

src/test/ui/borrowck/borrowck-borrow-immut-deref-of-box-as-mut.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0596]: cannot borrow `*a` as mutable, as `a` is not declared as mutable
22
--> $DIR/borrowck-borrow-immut-deref-of-box-as-mut.rs:12:5
33
|
4-
LL | let a: Box<_> = Box::new(A);
5-
| - help: consider changing this to be mutable: `mut a`
64
LL | a.foo();
75
| ^^^^^^^ cannot borrow as mutable
6+
|
7+
help: consider changing this to be mutable
8+
|
9+
LL | let mut a: Box<_> = Box::new(A);
10+
| +++
811

912
error: aborting due to previous error
1013

src/test/ui/borrowck/borrowck-mut-addr-of-imm-var.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
22
--> $DIR/borrowck-mut-addr-of-imm-var.rs:3:25
33
|
4-
LL | let x: isize = 3;
5-
| - help: consider changing this to be mutable: `mut x`
64
LL | let y: &mut isize = &mut x;
75
| ^^^^^^ cannot borrow as mutable
6+
|
7+
help: consider changing this to be mutable
8+
|
9+
LL | let mut x: isize = 3;
10+
| +++
811

912
error: aborting due to previous error
1013

src/test/ui/borrowck/borrowck-mut-slice-of-imm-vec.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable
22
--> $DIR/borrowck-mut-slice-of-imm-vec.rs:7:11
33
|
4-
LL | let v = vec![1, 2, 3];
5-
| - help: consider changing this to be mutable: `mut v`
64
LL | write(&mut v);
75
| ^^^^^^ cannot borrow as mutable
6+
|
7+
help: consider changing this to be mutable
8+
|
9+
LL | let mut v = vec![1, 2, 3];
10+
| +++
811

912
error: aborting due to previous error
1013

src/test/ui/borrowck/borrowck-overloaded-call.stderr

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ LL | use_mut(sp);
1111
error[E0596]: cannot borrow `s` as mutable, as it is not declared as mutable
1212
--> $DIR/borrowck-overloaded-call.rs:67:5
1313
|
14-
LL | let s = SFnMut {
15-
| - help: consider changing this to be mutable: `mut s`
16-
...
1714
LL | s(3);
1815
| ^ cannot borrow as mutable
16+
|
17+
help: consider changing this to be mutable
18+
|
19+
LL | let mut s = SFnMut {
20+
| +++
1921

2022
error[E0382]: use of moved value: `s`
2123
--> $DIR/borrowck-overloaded-call.rs:75:5

src/test/ui/borrowck/borrowck-ref-mut-of-imm.stderr

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
error[E0596]: cannot borrow `x.0` as mutable, as `x` is not declared as mutable
22
--> $DIR/borrowck-ref-mut-of-imm.rs:4:12
33
|
4-
LL | fn destructure(x: Option<isize>) -> isize {
5-
| - help: consider changing this to be mutable: `mut x`
6-
...
74
LL | Some(ref mut v) => *v
85
| ^^^^^^^^^ cannot borrow as mutable
6+
|
7+
help: consider changing this to be mutable
8+
|
9+
LL | fn destructure(mut x: Option<isize>) -> isize {
10+
| +++
911

1012
error: aborting due to previous error
1113

0 commit comments

Comments
 (0)