diff options
| -rw-r--r-- | tests/ui/assign-imm-local-twice.fixed | 21 | ||||
| -rw-r--r-- | tests/ui/assign-imm-local-twice.rs | 22 | ||||
| -rw-r--r-- | tests/ui/assign-imm-local-twice.stderr | 4 |
3 files changed, 38 insertions, 9 deletions
diff --git a/tests/ui/assign-imm-local-twice.fixed b/tests/ui/assign-imm-local-twice.fixed new file mode 100644 index 00000000000..dca994141bb --- /dev/null +++ b/tests/ui/assign-imm-local-twice.fixed @@ -0,0 +1,21 @@ +//! Check that we do not allow assigning twice to an immutable variable. This test also checks a +//! few pieces of borrowck diagnostics: +//! +//! - A multipart borrowck diagnostics that points out the first assignment to an immutable +//! variable, alongside violating assignments that follow subsequently. +//! - A suggestion diagnostics to make the immutable binding mutable. + +//@ run-rustfix + +fn main() { + let mut v: isize; + //~^ HELP consider making this binding mutable + //~| SUGGESTION mut + v = 1; + //~^ NOTE first assignment + println!("v={}", v); + v = 2; + //~^ ERROR cannot assign twice to immutable variable + //~| NOTE cannot assign twice to immutable + println!("v={}", v); +} diff --git a/tests/ui/assign-imm-local-twice.rs b/tests/ui/assign-imm-local-twice.rs index b2dfeb564d9..43437fa69fa 100644 --- a/tests/ui/assign-imm-local-twice.rs +++ b/tests/ui/assign-imm-local-twice.rs @@ -1,13 +1,21 @@ -fn test() { +//! Check that we do not allow assigning twice to an immutable variable. This test also checks a +//! few pieces of borrowck diagnostics: +//! +//! - A multipart borrowck diagnostics that points out the first assignment to an immutable +//! variable, alongside violating assignments that follow subsequently. +//! - A suggestion diagnostics to make the immutable binding mutable. + +//@ run-rustfix + +fn main() { let v: isize; //~^ HELP consider making this binding mutable //~| SUGGESTION mut - v = 1; //~ NOTE first assignment + v = 1; + //~^ NOTE first assignment println!("v={}", v); - v = 2; //~ ERROR cannot assign twice to immutable variable - //~| NOTE cannot assign twice to immutable + v = 2; + //~^ ERROR cannot assign twice to immutable variable + //~| NOTE cannot assign twice to immutable println!("v={}", v); } - -fn main() { -} diff --git a/tests/ui/assign-imm-local-twice.stderr b/tests/ui/assign-imm-local-twice.stderr index fda3aa3de1b..0a2138d0b96 100644 --- a/tests/ui/assign-imm-local-twice.stderr +++ b/tests/ui/assign-imm-local-twice.stderr @@ -1,9 +1,9 @@ error[E0384]: cannot assign twice to immutable variable `v` - --> $DIR/assign-imm-local-twice.rs:7:5 + --> $DIR/assign-imm-local-twice.rs:17:5 | LL | v = 1; | ----- first assignment to `v` -LL | println!("v={}", v); +... LL | v = 2; | ^^^^^ cannot assign twice to immutable variable | |
