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.
This commit is contained in:
James Addison 2021-04-12 23:29:09 +01:00
parent d0695c9081
commit 0174dd6f92
23 changed files with 36 additions and 36 deletions

View file

@ -1681,7 +1681,7 @@ pub(in crate::borrow_check) fn report_illegal_reassignment(
if decl.can_be_made_mutable() {
err.span_suggestion(
decl.source_info.span,
"make this binding mutable",
"consider making this binding mutable",
format!("mut {}", name),
Applicability::MachineApplicable,
);

View file

@ -1,6 +1,6 @@
fn test() {
let v: isize;
//~^ HELP make this binding mutable
//~^ HELP consider making this binding mutable
//~| SUGGESTION mut v
v = 1; //~ NOTE first assignment
println!("v={}", v);

View file

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

View file

@ -13,7 +13,7 @@ LL | pub async fn g(x: usize) {
| -
| |
| first assignment to `x`
| help: make this binding mutable: `mut x`
| help: consider making this binding mutable: `mut x`
LL | x += 1;
| ^^^^^^ cannot assign twice to immutable variable

View file

@ -29,7 +29,7 @@ LL | let x = 3;
| -
| |
| first assignment to `x`
| help: make this binding mutable: `mut x`
| help: consider making this binding mutable: `mut x`
LL | unsafe {
LL | llvm_asm!("nop" : "=r"(x));
| ^ cannot assign twice to immutable variable
@ -41,7 +41,7 @@ LL | let x = 3;
| -
| |
| first assignment to `x`
| help: make this binding mutable: `mut x`
| help: consider making this binding mutable: `mut x`
LL | unsafe {
LL | llvm_asm!("nop" : "+r"(x));
| ^ cannot assign twice to immutable variable

View file

@ -5,7 +5,7 @@ LL | x => {
| -
| |
| first assignment to `x`
| help: make this binding mutable: `mut x`
| help: consider making this binding mutable: `mut x`
LL | x += 1;
| ^^^^^^ cannot assign twice to immutable variable
@ -16,7 +16,7 @@ LL | E::Foo(x) => {
| -
| |
| first assignment to `x`
| help: make this binding mutable: `mut x`
| help: consider making this binding mutable: `mut x`
LL | x += 1;
| ^^^^^^ cannot assign twice to immutable variable
@ -27,7 +27,7 @@ LL | S { bar: x } => {
| -
| |
| first assignment to `x`
| help: make this binding mutable: `mut x`
| help: consider making this binding mutable: `mut x`
LL | x += 1;
| ^^^^^^ cannot assign twice to immutable variable
@ -38,7 +38,7 @@ LL | (x,) => {
| -
| |
| first assignment to `x`
| help: make this binding mutable: `mut x`
| help: consider making this binding mutable: `mut x`
LL | x += 1;
| ^^^^^^ cannot assign twice to immutable variable
@ -49,7 +49,7 @@ LL | [x,_,_] => {
| -
| |
| first assignment to `x`
| help: make this binding mutable: `mut x`
| help: consider making this binding mutable: `mut x`
LL | x += 1;
| ^^^^^^ cannot assign twice to immutable variable

View file

@ -2,7 +2,7 @@ error[E0384]: cannot assign to immutable argument `_x`
--> $DIR/immutable-arg.rs:2:5
|
LL | fn foo(_x: u32) {
| -- help: make this binding mutable: `mut _x`
| -- help: consider making this binding mutable: `mut _x`
LL | _x = 4;
| ^^^^^^ cannot assign to immutable argument

View file

@ -1,6 +1,6 @@
fn test_drop_replace() {
let b: Box<isize>;
//~^ HELP make this binding mutable
//~^ HELP consider making this binding mutable
//~| SUGGESTION mut b
b = Box::new(1); //~ NOTE first assignment
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
@ -9,13 +9,13 @@ fn test_drop_replace() {
fn test_call() {
let b = Box::new(1); //~ NOTE first assignment
//~| HELP make this binding mutable
//~| HELP consider making this binding mutable
//~| SUGGESTION mut b
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
//~| NOTE cannot assign twice to immutable
}
fn test_args(b: Box<i32>) { //~ HELP make this binding mutable
fn test_args(b: Box<i32>) { //~ HELP consider making this binding mutable
//~| SUGGESTION mut b
b = Box::new(2); //~ ERROR cannot assign to immutable argument `b`
//~| NOTE cannot assign to immutable argument

View file

@ -2,7 +2,7 @@ error[E0384]: cannot assign twice to immutable variable `b`
--> $DIR/issue-45199.rs:6:5
|
LL | let b: Box<isize>;
| - help: make this binding mutable: `mut b`
| - help: consider making this binding mutable: `mut b`
...
LL | b = Box::new(1);
| - first assignment to `b`
@ -16,7 +16,7 @@ LL | let b = Box::new(1);
| -
| |
| first assignment to `b`
| help: make this binding mutable: `mut b`
| help: consider making this binding mutable: `mut b`
...
LL | b = Box::new(2);
| ^ cannot assign twice to immutable variable
@ -25,7 +25,7 @@ error[E0384]: cannot assign to immutable argument `b`
--> $DIR/issue-45199.rs:20:5
|
LL | fn test_args(b: Box<i32>) {
| - help: make this binding mutable: `mut b`
| - help: consider making this binding mutable: `mut b`
LL |
LL | b = Box::new(2);
| ^ cannot assign to immutable argument

View file

@ -5,7 +5,7 @@ LL | let x = 42;
| -
| |
| first assignment to `x`
| help: make this binding mutable: `mut x`
| help: consider making this binding mutable: `mut x`
LL | x = 43;
| ^^^^^^ cannot assign twice to immutable variable

View file

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

View file

@ -2,7 +2,7 @@ error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/liveness-assign-imm-local-notes.rs:10:9
|
LL | let x;
| - help: make this binding mutable: `mut x`
| - help: consider making this binding mutable: `mut x`
...
LL | x = 2;
| ----- first assignment to `x`
@ -13,7 +13,7 @@ error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/liveness-assign-imm-local-notes.rs:21:13
|
LL | let x;
| - help: make this binding mutable: `mut x`
| - help: consider making this binding mutable: `mut x`
...
LL | x = 2;
| ----- first assignment to `x`
@ -24,7 +24,7 @@ error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/liveness-assign-imm-local-notes.rs:30:13
|
LL | let x;
| - help: make this binding mutable: `mut x`
| - help: consider making this binding mutable: `mut x`
...
LL | x = 1;
| ^^^^^ cannot assign twice to immutable variable
@ -33,7 +33,7 @@ error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/liveness-assign-imm-local-notes.rs:32:13
|
LL | let x;
| - help: make this binding mutable: `mut x`
| - help: consider making this binding mutable: `mut x`
...
LL | x = 1;
| ----- first assignment to `x`

View file

@ -1,6 +1,6 @@
fn test() {
let v: isize;
//~^ HELP make this binding mutable
//~^ HELP consider making this binding mutable
//~| SUGGESTION mut v
loop {
v = 1; //~ ERROR cannot assign twice to immutable variable `v`

View file

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

View file

@ -1,6 +1,6 @@
fn test() {
let v: isize;
//~^ HELP make this binding mutable
//~^ HELP consider making this binding mutable
//~| SUGGESTION mut v
v = 2; //~ NOTE first assignment
v += 1; //~ ERROR cannot assign twice to immutable variable `v`

View file

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

View file

@ -1,6 +1,6 @@
fn test() {
let b = Box::new(1); //~ NOTE first assignment
//~| HELP make this binding mutable
//~| HELP consider making this binding mutable
//~| SUGGESTION mut b
drop(b);
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`

View file

@ -5,7 +5,7 @@ LL | let b = Box::new(1);
| -
| |
| first assignment to `b`
| help: make this binding mutable: `mut b`
| help: consider making this binding mutable: `mut b`
...
LL | b = Box::new(2);
| ^ cannot assign twice to immutable variable

View file

@ -1,6 +1,6 @@
fn test() {
let v: isize = 1; //~ NOTE first assignment
//~| HELP make this binding mutable
//~| HELP consider making this binding mutable
//~| SUGGESTION mut v
v.clone();
v = 2; //~ ERROR cannot assign twice to immutable variable `v`

View file

@ -5,7 +5,7 @@ LL | let v: isize = 1;
| -
| |
| first assignment to `v`
| help: make this binding mutable: `mut v`
| help: consider making this binding mutable: `mut v`
...
LL | v = 2;
| ^^^^^ cannot assign twice to immutable variable

View file

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

View file

@ -5,7 +5,7 @@ LL | let &mut x = foo;
| -
| |
| first assignment to `x`
| help: make this binding mutable: `mut x`
| help: consider making this binding mutable: `mut x`
LL | x += 1;
| ^^^^^^ cannot assign twice to immutable variable

View file

@ -16,7 +16,7 @@ LL | let [ref _x0_hold, _x1, ref xs_hold @ ..] = arr;
| ---
| |
| first assignment to `_x1`
| help: make this binding mutable: `mut _x1`
| help: consider making this binding mutable: `mut _x1`
LL | _x1 = U;
| ^^^^^^^ cannot assign twice to immutable variable
@ -74,7 +74,7 @@ LL | let (ref _x0, _x1, ref _x2, ..) = tup;
| ---
| |
| first assignment to `_x1`
| help: make this binding mutable: `mut _x1`
| help: consider making this binding mutable: `mut _x1`
LL | _x1 = U;
| ^^^^^^^ cannot assign twice to immutable variable