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
This commit is contained in:
commit
c7c59d7c3b
23 changed files with 36 additions and 36 deletions
|
@ -1681,7 +1681,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
if decl.can_be_made_mutable() {
|
if decl.can_be_made_mutable() {
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
decl.source_info.span,
|
decl.source_info.span,
|
||||||
"make this binding mutable",
|
"consider making this binding mutable",
|
||||||
format!("mut {}", name),
|
format!("mut {}", name),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
fn test() {
|
fn test() {
|
||||||
let v: isize;
|
let v: isize;
|
||||||
//~^ HELP make this binding mutable
|
//~^ HELP consider making this binding mutable
|
||||||
//~| SUGGESTION mut v
|
//~| SUGGESTION mut v
|
||||||
v = 1; //~ NOTE first assignment
|
v = 1; //~ NOTE first assignment
|
||||||
println!("v={}", v);
|
println!("v={}", v);
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0384]: cannot assign twice to immutable variable `v`
|
||||||
--> $DIR/assign-imm-local-twice.rs:7:5
|
--> $DIR/assign-imm-local-twice.rs:7:5
|
||||||
|
|
|
|
||||||
LL | let v: isize;
|
LL | let v: isize;
|
||||||
| - help: make this binding mutable: `mut v`
|
| - help: consider making this binding mutable: `mut v`
|
||||||
...
|
...
|
||||||
LL | v = 1;
|
LL | v = 1;
|
||||||
| ----- first assignment to `v`
|
| ----- first assignment to `v`
|
||||||
|
|
|
@ -13,7 +13,7 @@ LL | pub async fn g(x: usize) {
|
||||||
| -
|
| -
|
||||||
| |
|
| |
|
||||||
| first assignment to `x`
|
| first assignment to `x`
|
||||||
| help: make this binding mutable: `mut x`
|
| help: consider making this binding mutable: `mut x`
|
||||||
LL | x += 1;
|
LL | x += 1;
|
||||||
| ^^^^^^ cannot assign twice to immutable variable
|
| ^^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ LL | let x = 3;
|
||||||
| -
|
| -
|
||||||
| |
|
| |
|
||||||
| first assignment to `x`
|
| first assignment to `x`
|
||||||
| help: make this binding mutable: `mut x`
|
| help: consider making this binding mutable: `mut x`
|
||||||
LL | unsafe {
|
LL | unsafe {
|
||||||
LL | llvm_asm!("nop" : "=r"(x));
|
LL | llvm_asm!("nop" : "=r"(x));
|
||||||
| ^ cannot assign twice to immutable variable
|
| ^ cannot assign twice to immutable variable
|
||||||
|
@ -41,7 +41,7 @@ LL | let x = 3;
|
||||||
| -
|
| -
|
||||||
| |
|
| |
|
||||||
| first assignment to `x`
|
| first assignment to `x`
|
||||||
| help: make this binding mutable: `mut x`
|
| help: consider making this binding mutable: `mut x`
|
||||||
LL | unsafe {
|
LL | unsafe {
|
||||||
LL | llvm_asm!("nop" : "+r"(x));
|
LL | llvm_asm!("nop" : "+r"(x));
|
||||||
| ^ cannot assign twice to immutable variable
|
| ^ cannot assign twice to immutable variable
|
||||||
|
|
|
@ -5,7 +5,7 @@ LL | x => {
|
||||||
| -
|
| -
|
||||||
| |
|
| |
|
||||||
| first assignment to `x`
|
| first assignment to `x`
|
||||||
| help: make this binding mutable: `mut x`
|
| help: consider making this binding mutable: `mut x`
|
||||||
LL | x += 1;
|
LL | x += 1;
|
||||||
| ^^^^^^ cannot assign twice to immutable variable
|
| ^^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ LL | E::Foo(x) => {
|
||||||
| -
|
| -
|
||||||
| |
|
| |
|
||||||
| first assignment to `x`
|
| first assignment to `x`
|
||||||
| help: make this binding mutable: `mut x`
|
| help: consider making this binding mutable: `mut x`
|
||||||
LL | x += 1;
|
LL | x += 1;
|
||||||
| ^^^^^^ cannot assign twice to immutable variable
|
| ^^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ LL | S { bar: x } => {
|
||||||
| -
|
| -
|
||||||
| |
|
| |
|
||||||
| first assignment to `x`
|
| first assignment to `x`
|
||||||
| help: make this binding mutable: `mut x`
|
| help: consider making this binding mutable: `mut x`
|
||||||
LL | x += 1;
|
LL | x += 1;
|
||||||
| ^^^^^^ cannot assign twice to immutable variable
|
| ^^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ LL | (x,) => {
|
||||||
| -
|
| -
|
||||||
| |
|
| |
|
||||||
| first assignment to `x`
|
| first assignment to `x`
|
||||||
| help: make this binding mutable: `mut x`
|
| help: consider making this binding mutable: `mut x`
|
||||||
LL | x += 1;
|
LL | x += 1;
|
||||||
| ^^^^^^ cannot assign twice to immutable variable
|
| ^^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ LL | [x,_,_] => {
|
||||||
| -
|
| -
|
||||||
| |
|
| |
|
||||||
| first assignment to `x`
|
| first assignment to `x`
|
||||||
| help: make this binding mutable: `mut x`
|
| help: consider making this binding mutable: `mut x`
|
||||||
LL | x += 1;
|
LL | x += 1;
|
||||||
| ^^^^^^ cannot assign twice to immutable variable
|
| ^^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0384]: cannot assign to immutable argument `_x`
|
||||||
--> $DIR/immutable-arg.rs:2:5
|
--> $DIR/immutable-arg.rs:2:5
|
||||||
|
|
|
|
||||||
LL | fn foo(_x: u32) {
|
LL | fn foo(_x: u32) {
|
||||||
| -- help: make this binding mutable: `mut _x`
|
| -- help: consider making this binding mutable: `mut _x`
|
||||||
LL | _x = 4;
|
LL | _x = 4;
|
||||||
| ^^^^^^ cannot assign to immutable argument
|
| ^^^^^^ cannot assign to immutable argument
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
fn test_drop_replace() {
|
fn test_drop_replace() {
|
||||||
let b: Box<isize>;
|
let b: Box<isize>;
|
||||||
//~^ HELP make this binding mutable
|
//~^ HELP consider making this binding mutable
|
||||||
//~| SUGGESTION mut b
|
//~| SUGGESTION mut b
|
||||||
b = Box::new(1); //~ NOTE first assignment
|
b = Box::new(1); //~ NOTE first assignment
|
||||||
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
|
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
|
||||||
|
@ -9,13 +9,13 @@ fn test_drop_replace() {
|
||||||
|
|
||||||
fn test_call() {
|
fn test_call() {
|
||||||
let b = Box::new(1); //~ NOTE first assignment
|
let b = Box::new(1); //~ NOTE first assignment
|
||||||
//~| HELP make this binding mutable
|
//~| HELP consider making this binding mutable
|
||||||
//~| SUGGESTION mut b
|
//~| SUGGESTION mut b
|
||||||
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
|
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
|
||||||
//~| NOTE cannot assign twice to immutable
|
//~| 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
|
//~| SUGGESTION mut b
|
||||||
b = Box::new(2); //~ ERROR cannot assign to immutable argument `b`
|
b = Box::new(2); //~ ERROR cannot assign to immutable argument `b`
|
||||||
//~| NOTE cannot assign to immutable argument
|
//~| NOTE cannot assign to immutable argument
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0384]: cannot assign twice to immutable variable `b`
|
||||||
--> $DIR/issue-45199.rs:6:5
|
--> $DIR/issue-45199.rs:6:5
|
||||||
|
|
|
|
||||||
LL | let b: Box<isize>;
|
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);
|
LL | b = Box::new(1);
|
||||||
| - first assignment to `b`
|
| - first assignment to `b`
|
||||||
|
@ -16,7 +16,7 @@ LL | let b = Box::new(1);
|
||||||
| -
|
| -
|
||||||
| |
|
| |
|
||||||
| first assignment to `b`
|
| first assignment to `b`
|
||||||
| help: make this binding mutable: `mut b`
|
| help: consider making this binding mutable: `mut b`
|
||||||
...
|
...
|
||||||
LL | b = Box::new(2);
|
LL | b = Box::new(2);
|
||||||
| ^ cannot assign twice to immutable variable
|
| ^ cannot assign twice to immutable variable
|
||||||
|
@ -25,7 +25,7 @@ error[E0384]: cannot assign to immutable argument `b`
|
||||||
--> $DIR/issue-45199.rs:20:5
|
--> $DIR/issue-45199.rs:20:5
|
||||||
|
|
|
|
||||||
LL | fn test_args(b: Box<i32>) {
|
LL | fn test_args(b: Box<i32>) {
|
||||||
| - help: make this binding mutable: `mut b`
|
| - help: consider making this binding mutable: `mut b`
|
||||||
LL |
|
LL |
|
||||||
LL | b = Box::new(2);
|
LL | b = Box::new(2);
|
||||||
| ^ cannot assign to immutable argument
|
| ^ cannot assign to immutable argument
|
||||||
|
|
|
@ -5,7 +5,7 @@ LL | let x = 42;
|
||||||
| -
|
| -
|
||||||
| |
|
| |
|
||||||
| first assignment to `x`
|
| first assignment to `x`
|
||||||
| help: make this binding mutable: `mut x`
|
| help: consider making this binding mutable: `mut x`
|
||||||
LL | x = 43;
|
LL | x = 43;
|
||||||
| ^^^^^^ cannot assign twice to immutable variable
|
| ^^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ error[E0384]: cannot assign to immutable argument `y`
|
||||||
--> $DIR/ex3-both-anon-regions-one-is-struct-2.rs:4:5
|
--> $DIR/ex3-both-anon-regions-one-is-struct-2.rs:4:5
|
||||||
|
|
|
|
||||||
LL | fn foo(mut x: Ref, y: &u32) {
|
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;
|
LL | y = x.b;
|
||||||
| ^^^^^^^ cannot assign to immutable argument
|
| ^^^^^^^ cannot assign to immutable argument
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0384]: cannot assign twice to immutable variable `x`
|
||||||
--> $DIR/liveness-assign-imm-local-notes.rs:10:9
|
--> $DIR/liveness-assign-imm-local-notes.rs:10:9
|
||||||
|
|
|
|
||||||
LL | let x;
|
LL | let x;
|
||||||
| - help: make this binding mutable: `mut x`
|
| - help: consider making this binding mutable: `mut x`
|
||||||
...
|
...
|
||||||
LL | x = 2;
|
LL | x = 2;
|
||||||
| ----- first assignment to `x`
|
| ----- 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
|
--> $DIR/liveness-assign-imm-local-notes.rs:21:13
|
||||||
|
|
|
|
||||||
LL | let x;
|
LL | let x;
|
||||||
| - help: make this binding mutable: `mut x`
|
| - help: consider making this binding mutable: `mut x`
|
||||||
...
|
...
|
||||||
LL | x = 2;
|
LL | x = 2;
|
||||||
| ----- first assignment to `x`
|
| ----- 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
|
--> $DIR/liveness-assign-imm-local-notes.rs:30:13
|
||||||
|
|
|
|
||||||
LL | let x;
|
LL | let x;
|
||||||
| - help: make this binding mutable: `mut x`
|
| - help: consider making this binding mutable: `mut x`
|
||||||
...
|
...
|
||||||
LL | x = 1;
|
LL | x = 1;
|
||||||
| ^^^^^ cannot assign twice to immutable variable
|
| ^^^^^ 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
|
--> $DIR/liveness-assign-imm-local-notes.rs:32:13
|
||||||
|
|
|
|
||||||
LL | let x;
|
LL | let x;
|
||||||
| - help: make this binding mutable: `mut x`
|
| - help: consider making this binding mutable: `mut x`
|
||||||
...
|
...
|
||||||
LL | x = 1;
|
LL | x = 1;
|
||||||
| ----- first assignment to `x`
|
| ----- first assignment to `x`
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
fn test() {
|
fn test() {
|
||||||
let v: isize;
|
let v: isize;
|
||||||
//~^ HELP make this binding mutable
|
//~^ HELP consider making this binding mutable
|
||||||
//~| SUGGESTION mut v
|
//~| SUGGESTION mut v
|
||||||
loop {
|
loop {
|
||||||
v = 1; //~ ERROR cannot assign twice to immutable variable `v`
|
v = 1; //~ ERROR cannot assign twice to immutable variable `v`
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0384]: cannot assign twice to immutable variable `v`
|
||||||
--> $DIR/liveness-assign-imm-local-in-loop.rs:6:9
|
--> $DIR/liveness-assign-imm-local-in-loop.rs:6:9
|
||||||
|
|
|
|
||||||
LL | let v: isize;
|
LL | let v: isize;
|
||||||
| - help: make this binding mutable: `mut v`
|
| - help: consider making this binding mutable: `mut v`
|
||||||
...
|
...
|
||||||
LL | v = 1;
|
LL | v = 1;
|
||||||
| ^^^^^ cannot assign twice to immutable variable
|
| ^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
fn test() {
|
fn test() {
|
||||||
let v: isize;
|
let v: isize;
|
||||||
//~^ HELP make this binding mutable
|
//~^ HELP consider making this binding mutable
|
||||||
//~| SUGGESTION mut v
|
//~| SUGGESTION mut v
|
||||||
v = 2; //~ NOTE first assignment
|
v = 2; //~ NOTE first assignment
|
||||||
v += 1; //~ ERROR cannot assign twice to immutable variable `v`
|
v += 1; //~ ERROR cannot assign twice to immutable variable `v`
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0384]: cannot assign twice to immutable variable `v`
|
||||||
--> $DIR/liveness-assign-imm-local-in-op-eq.rs:6:5
|
--> $DIR/liveness-assign-imm-local-in-op-eq.rs:6:5
|
||||||
|
|
|
|
||||||
LL | let v: isize;
|
LL | let v: isize;
|
||||||
| - help: make this binding mutable: `mut v`
|
| - help: consider making this binding mutable: `mut v`
|
||||||
...
|
...
|
||||||
LL | v = 2;
|
LL | v = 2;
|
||||||
| ----- first assignment to `v`
|
| ----- first assignment to `v`
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
fn test() {
|
fn test() {
|
||||||
let b = Box::new(1); //~ NOTE first assignment
|
let b = Box::new(1); //~ NOTE first assignment
|
||||||
//~| HELP make this binding mutable
|
//~| HELP consider making this binding mutable
|
||||||
//~| SUGGESTION mut b
|
//~| SUGGESTION mut b
|
||||||
drop(b);
|
drop(b);
|
||||||
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
|
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
|
||||||
|
|
|
@ -5,7 +5,7 @@ LL | let b = Box::new(1);
|
||||||
| -
|
| -
|
||||||
| |
|
| |
|
||||||
| first assignment to `b`
|
| first assignment to `b`
|
||||||
| help: make this binding mutable: `mut b`
|
| help: consider making this binding mutable: `mut b`
|
||||||
...
|
...
|
||||||
LL | b = Box::new(2);
|
LL | b = Box::new(2);
|
||||||
| ^ cannot assign twice to immutable variable
|
| ^ cannot assign twice to immutable variable
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
fn test() {
|
fn test() {
|
||||||
let v: isize = 1; //~ NOTE first assignment
|
let v: isize = 1; //~ NOTE first assignment
|
||||||
//~| HELP make this binding mutable
|
//~| HELP consider making this binding mutable
|
||||||
//~| SUGGESTION mut v
|
//~| SUGGESTION mut v
|
||||||
v.clone();
|
v.clone();
|
||||||
v = 2; //~ ERROR cannot assign twice to immutable variable `v`
|
v = 2; //~ ERROR cannot assign twice to immutable variable `v`
|
||||||
|
|
|
@ -5,7 +5,7 @@ LL | let v: isize = 1;
|
||||||
| -
|
| -
|
||||||
| |
|
| |
|
||||||
| first assignment to `v`
|
| first assignment to `v`
|
||||||
| help: make this binding mutable: `mut v`
|
| help: consider making this binding mutable: `mut v`
|
||||||
...
|
...
|
||||||
LL | v = 2;
|
LL | v = 2;
|
||||||
| ^^^^^ cannot assign twice to immutable variable
|
| ^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0384]: cannot assign twice to immutable variable `x`
|
||||||
--> $DIR/llvm-asm-out-assign-imm.rs:25:39
|
--> $DIR/llvm-asm-out-assign-imm.rs:25:39
|
||||||
|
|
|
|
||||||
LL | let x: isize;
|
LL | let x: isize;
|
||||||
| - help: make this binding mutable: `mut x`
|
| - help: consider making this binding mutable: `mut x`
|
||||||
LL | x = 1;
|
LL | x = 1;
|
||||||
| ----- first assignment to `x`
|
| ----- first assignment to `x`
|
||||||
...
|
...
|
||||||
|
|
|
@ -5,7 +5,7 @@ LL | let &mut x = foo;
|
||||||
| -
|
| -
|
||||||
| |
|
| |
|
||||||
| first assignment to `x`
|
| first assignment to `x`
|
||||||
| help: make this binding mutable: `mut x`
|
| help: consider making this binding mutable: `mut x`
|
||||||
LL | x += 1;
|
LL | x += 1;
|
||||||
| ^^^^^^ cannot assign twice to immutable variable
|
| ^^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ LL | let [ref _x0_hold, _x1, ref xs_hold @ ..] = arr;
|
||||||
| ---
|
| ---
|
||||||
| |
|
| |
|
||||||
| first assignment to `_x1`
|
| first assignment to `_x1`
|
||||||
| help: make this binding mutable: `mut _x1`
|
| help: consider making this binding mutable: `mut _x1`
|
||||||
LL | _x1 = U;
|
LL | _x1 = U;
|
||||||
| ^^^^^^^ cannot assign twice to immutable variable
|
| ^^^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ LL | let (ref _x0, _x1, ref _x2, ..) = tup;
|
||||||
| ---
|
| ---
|
||||||
| |
|
| |
|
||||||
| first assignment to `_x1`
|
| first assignment to `_x1`
|
||||||
| help: make this binding mutable: `mut _x1`
|
| help: consider making this binding mutable: `mut _x1`
|
||||||
LL | _x1 = U;
|
LL | _x1 = U;
|
||||||
| ^^^^^^^ cannot assign twice to immutable variable
|
| ^^^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue