Skip to content

Commit c7c59d7

Browse files
authored
Rollup merge of #84172 - jayaddison:compiler/E0384-reduce-assertiveness, r=petrochenkov
Compiler error messages: reduce assertiveness of message E0384 This message is emitted as guidance by the compiler when a developer attempts to reassign a value to an immutable variable. Following the message will always currently work, but it may not always be the best course of action; following the 'consider ...' messaging pattern provides a hint to the developer that it could be wise to explore other alternatives. Resolves #84144
2 parents a5ec5cf + ff47e97 commit c7c59d7

23 files changed

+36
-36
lines changed

compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16811681
if decl.can_be_made_mutable() {
16821682
err.span_suggestion(
16831683
decl.source_info.span,
1684-
"make this binding mutable",
1684+
"consider making this binding mutable",
16851685
format!("mut {}", name),
16861686
Applicability::MachineApplicable,
16871687
);

src/test/ui/assign-imm-local-twice.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn test() {
22
let v: isize;
3-
//~^ HELP make this binding mutable
3+
//~^ HELP consider making this binding mutable
44
//~| SUGGESTION mut v
55
v = 1; //~ NOTE first assignment
66
println!("v={}", v);

src/test/ui/assign-imm-local-twice.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0384]: cannot assign twice to immutable variable `v`
22
--> $DIR/assign-imm-local-twice.rs:7:5
33
|
44
LL | let v: isize;
5-
| - help: make this binding mutable: `mut v`
5+
| - help: consider making this binding mutable: `mut v`
66
...
77
LL | v = 1;
88
| ----- first assignment to `v`

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | pub async fn g(x: usize) {
1313
| -
1414
| |
1515
| first assignment to `x`
16-
| help: make this binding mutable: `mut x`
16+
| help: consider making this binding mutable: `mut x`
1717
LL | x += 1;
1818
| ^^^^^^ cannot assign twice to immutable variable
1919

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ LL | let x = 3;
2929
| -
3030
| |
3131
| first assignment to `x`
32-
| help: make this binding mutable: `mut x`
32+
| help: consider making this binding mutable: `mut x`
3333
LL | unsafe {
3434
LL | llvm_asm!("nop" : "=r"(x));
3535
| ^ cannot assign twice to immutable variable
@@ -41,7 +41,7 @@ LL | let x = 3;
4141
| -
4242
| |
4343
| first assignment to `x`
44-
| help: make this binding mutable: `mut x`
44+
| help: consider making this binding mutable: `mut x`
4545
LL | unsafe {
4646
LL | llvm_asm!("nop" : "+r"(x));
4747
| ^ cannot assign twice to immutable variable

src/test/ui/borrowck/borrowck-match-binding-is-assignment.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | x => {
55
| -
66
| |
77
| first assignment to `x`
8-
| help: make this binding mutable: `mut x`
8+
| help: consider making this binding mutable: `mut x`
99
LL | x += 1;
1010
| ^^^^^^ cannot assign twice to immutable variable
1111

@@ -16,7 +16,7 @@ LL | E::Foo(x) => {
1616
| -
1717
| |
1818
| first assignment to `x`
19-
| help: make this binding mutable: `mut x`
19+
| help: consider making this binding mutable: `mut x`
2020
LL | x += 1;
2121
| ^^^^^^ cannot assign twice to immutable variable
2222

@@ -27,7 +27,7 @@ LL | S { bar: x } => {
2727
| -
2828
| |
2929
| first assignment to `x`
30-
| help: make this binding mutable: `mut x`
30+
| help: consider making this binding mutable: `mut x`
3131
LL | x += 1;
3232
| ^^^^^^ cannot assign twice to immutable variable
3333

@@ -38,7 +38,7 @@ LL | (x,) => {
3838
| -
3939
| |
4040
| first assignment to `x`
41-
| help: make this binding mutable: `mut x`
41+
| help: consider making this binding mutable: `mut x`
4242
LL | x += 1;
4343
| ^^^^^^ cannot assign twice to immutable variable
4444

@@ -49,7 +49,7 @@ LL | [x,_,_] => {
4949
| -
5050
| |
5151
| first assignment to `x`
52-
| help: make this binding mutable: `mut x`
52+
| help: consider making this binding mutable: `mut x`
5353
LL | x += 1;
5454
| ^^^^^^ cannot assign twice to immutable variable
5555

src/test/ui/borrowck/immutable-arg.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0384]: cannot assign to immutable argument `_x`
22
--> $DIR/immutable-arg.rs:2:5
33
|
44
LL | fn foo(_x: u32) {
5-
| -- help: make this binding mutable: `mut _x`
5+
| -- help: consider making this binding mutable: `mut _x`
66
LL | _x = 4;
77
| ^^^^^^ cannot assign to immutable argument
88

src/test/ui/borrowck/issue-45199.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn test_drop_replace() {
22
let b: Box<isize>;
3-
//~^ HELP make this binding mutable
3+
//~^ HELP consider making this binding mutable
44
//~| SUGGESTION mut b
55
b = Box::new(1); //~ NOTE first assignment
66
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
@@ -9,13 +9,13 @@ fn test_drop_replace() {
99

1010
fn test_call() {
1111
let b = Box::new(1); //~ NOTE first assignment
12-
//~| HELP make this binding mutable
12+
//~| HELP consider making this binding mutable
1313
//~| SUGGESTION mut b
1414
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
1515
//~| NOTE cannot assign twice to immutable
1616
}
1717

18-
fn test_args(b: Box<i32>) { //~ HELP make this binding mutable
18+
fn test_args(b: Box<i32>) { //~ HELP consider making this binding mutable
1919
//~| SUGGESTION mut b
2020
b = Box::new(2); //~ ERROR cannot assign to immutable argument `b`
2121
//~| NOTE cannot assign to immutable argument

src/test/ui/borrowck/issue-45199.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0384]: cannot assign twice to immutable variable `b`
22
--> $DIR/issue-45199.rs:6:5
33
|
44
LL | let b: Box<isize>;
5-
| - help: make this binding mutable: `mut b`
5+
| - help: consider making this binding mutable: `mut b`
66
...
77
LL | b = Box::new(1);
88
| - first assignment to `b`
@@ -16,7 +16,7 @@ LL | let b = Box::new(1);
1616
| -
1717
| |
1818
| first assignment to `b`
19-
| help: make this binding mutable: `mut b`
19+
| help: consider making this binding mutable: `mut b`
2020
...
2121
LL | b = Box::new(2);
2222
| ^ cannot assign twice to immutable variable
@@ -25,7 +25,7 @@ error[E0384]: cannot assign to immutable argument `b`
2525
--> $DIR/issue-45199.rs:20:5
2626
|
2727
LL | fn test_args(b: Box<i32>) {
28-
| - help: make this binding mutable: `mut b`
28+
| - help: consider making this binding mutable: `mut b`
2929
LL |
3030
LL | b = Box::new(2);
3131
| ^ cannot assign to immutable argument

src/test/ui/command-line-diagnostics.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let x = 42;
55
| -
66
| |
77
| first assignment to `x`
8-
| help: make this binding mutable: `mut x`
8+
| help: consider making this binding mutable: `mut x`
99
LL | x = 43;
1010
| ^^^^^^ cannot assign twice to immutable variable
1111

src/test/ui/lifetimes/lifetime-errors/ex3-both-anon-regions-one-is-struct-2.nll.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ error[E0384]: cannot assign to immutable argument `y`
1212
--> $DIR/ex3-both-anon-regions-one-is-struct-2.rs:4:5
1313
|
1414
LL | fn foo(mut x: Ref, y: &u32) {
15-
| - help: make this binding mutable: `mut y`
15+
| - help: consider making this binding mutable: `mut y`
1616
LL | y = x.b;
1717
| ^^^^^^^ cannot assign to immutable argument
1818

src/test/ui/lifetimes/lifetime-errors/liveness-assign-imm-local-notes.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0384]: cannot assign twice to immutable variable `x`
22
--> $DIR/liveness-assign-imm-local-notes.rs:10:9
33
|
44
LL | let x;
5-
| - help: make this binding mutable: `mut x`
5+
| - help: consider making this binding mutable: `mut x`
66
...
77
LL | x = 2;
88
| ----- first assignment to `x`
@@ -13,7 +13,7 @@ error[E0384]: cannot assign twice to immutable variable `x`
1313
--> $DIR/liveness-assign-imm-local-notes.rs:21:13
1414
|
1515
LL | let x;
16-
| - help: make this binding mutable: `mut x`
16+
| - help: consider making this binding mutable: `mut x`
1717
...
1818
LL | x = 2;
1919
| ----- first assignment to `x`
@@ -24,7 +24,7 @@ error[E0384]: cannot assign twice to immutable variable `x`
2424
--> $DIR/liveness-assign-imm-local-notes.rs:30:13
2525
|
2626
LL | let x;
27-
| - help: make this binding mutable: `mut x`
27+
| - help: consider making this binding mutable: `mut x`
2828
...
2929
LL | x = 1;
3030
| ^^^^^ cannot assign twice to immutable variable
@@ -33,7 +33,7 @@ error[E0384]: cannot assign twice to immutable variable `x`
3333
--> $DIR/liveness-assign-imm-local-notes.rs:32:13
3434
|
3535
LL | let x;
36-
| - help: make this binding mutable: `mut x`
36+
| - help: consider making this binding mutable: `mut x`
3737
...
3838
LL | x = 1;
3939
| ----- first assignment to `x`

src/test/ui/liveness/liveness-assign/liveness-assign-imm-local-in-loop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn test() {
22
let v: isize;
3-
//~^ HELP make this binding mutable
3+
//~^ HELP consider making this binding mutable
44
//~| SUGGESTION mut v
55
loop {
66
v = 1; //~ ERROR cannot assign twice to immutable variable `v`

src/test/ui/liveness/liveness-assign/liveness-assign-imm-local-in-loop.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0384]: cannot assign twice to immutable variable `v`
22
--> $DIR/liveness-assign-imm-local-in-loop.rs:6:9
33
|
44
LL | let v: isize;
5-
| - help: make this binding mutable: `mut v`
5+
| - help: consider making this binding mutable: `mut v`
66
...
77
LL | v = 1;
88
| ^^^^^ cannot assign twice to immutable variable

src/test/ui/liveness/liveness-assign/liveness-assign-imm-local-in-op-eq.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn test() {
22
let v: isize;
3-
//~^ HELP make this binding mutable
3+
//~^ HELP consider making this binding mutable
44
//~| SUGGESTION mut v
55
v = 2; //~ NOTE first assignment
66
v += 1; //~ ERROR cannot assign twice to immutable variable `v`

src/test/ui/liveness/liveness-assign/liveness-assign-imm-local-in-op-eq.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0384]: cannot assign twice to immutable variable `v`
22
--> $DIR/liveness-assign-imm-local-in-op-eq.rs:6:5
33
|
44
LL | let v: isize;
5-
| - help: make this binding mutable: `mut v`
5+
| - help: consider making this binding mutable: `mut v`
66
...
77
LL | v = 2;
88
| ----- first assignment to `v`

src/test/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn test() {
22
let b = Box::new(1); //~ NOTE first assignment
3-
//~| HELP make this binding mutable
3+
//~| HELP consider making this binding mutable
44
//~| SUGGESTION mut b
55
drop(b);
66
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`

src/test/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let b = Box::new(1);
55
| -
66
| |
77
| first assignment to `b`
8-
| help: make this binding mutable: `mut b`
8+
| help: consider making this binding mutable: `mut b`
99
...
1010
LL | b = Box::new(2);
1111
| ^ cannot assign twice to immutable variable

src/test/ui/liveness/liveness-assign/liveness-assign-imm-local-with-init.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn test() {
22
let v: isize = 1; //~ NOTE first assignment
3-
//~| HELP make this binding mutable
3+
//~| HELP consider making this binding mutable
44
//~| SUGGESTION mut v
55
v.clone();
66
v = 2; //~ ERROR cannot assign twice to immutable variable `v`

src/test/ui/liveness/liveness-assign/liveness-assign-imm-local-with-init.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let v: isize = 1;
55
| -
66
| |
77
| first assignment to `v`
8-
| help: make this binding mutable: `mut v`
8+
| help: consider making this binding mutable: `mut v`
99
...
1010
LL | v = 2;
1111
| ^^^^^ cannot assign twice to immutable variable

src/test/ui/llvm-asm/llvm-asm-out-assign-imm.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0384]: cannot assign twice to immutable variable `x`
22
--> $DIR/llvm-asm-out-assign-imm.rs:25:39
33
|
44
LL | let x: isize;
5-
| - help: make this binding mutable: `mut x`
5+
| - help: consider making this binding mutable: `mut x`
66
LL | x = 1;
77
| ----- first assignment to `x`
88
...

src/test/ui/mut/mut-pattern-internal-mutability.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let &mut x = foo;
55
| -
66
| |
77
| first assignment to `x`
8-
| help: make this binding mutable: `mut x`
8+
| help: consider making this binding mutable: `mut x`
99
LL | x += 1;
1010
| ^^^^^^ cannot assign twice to immutable variable
1111

src/test/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ LL | let [ref _x0_hold, _x1, ref xs_hold @ ..] = arr;
1616
| ---
1717
| |
1818
| first assignment to `_x1`
19-
| help: make this binding mutable: `mut _x1`
19+
| help: consider making this binding mutable: `mut _x1`
2020
LL | _x1 = U;
2121
| ^^^^^^^ cannot assign twice to immutable variable
2222

@@ -74,7 +74,7 @@ LL | let (ref _x0, _x1, ref _x2, ..) = tup;
7474
| ---
7575
| |
7676
| first assignment to `_x1`
77-
| help: make this binding mutable: `mut _x1`
77+
| help: consider making this binding mutable: `mut _x1`
7878
LL | _x1 = U;
7979
| ^^^^^^^ cannot assign twice to immutable variable
8080

0 commit comments

Comments
 (0)