diff options
Diffstat (limited to 'tests/ui/liveness/liveness-assign')
8 files changed, 104 insertions, 0 deletions
diff --git a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-loop.rs b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-loop.rs new file mode 100644 index 000000000..08911c5bd --- /dev/null +++ b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-loop.rs @@ -0,0 +1,12 @@ +fn test() { + let v: isize; + //~^ HELP consider making this binding mutable + //~| SUGGESTION mut v + loop { + v = 1; //~ ERROR cannot assign twice to immutable variable `v` + //~| NOTE cannot assign twice to immutable variable + } +} + +fn main() { +} diff --git a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-loop.stderr b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-loop.stderr new file mode 100644 index 000000000..66cdce7da --- /dev/null +++ b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-loop.stderr @@ -0,0 +1,12 @@ +error[E0384]: cannot assign twice to immutable variable `v` + --> $DIR/liveness-assign-imm-local-in-loop.rs:6:9 + | +LL | let v: isize; + | - help: consider making this binding mutable: `mut v` +... +LL | v = 1; + | ^^^^^ cannot assign twice to immutable variable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0384`. diff --git a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-op-eq.rs b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-op-eq.rs new file mode 100644 index 000000000..1752d9690 --- /dev/null +++ b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-op-eq.rs @@ -0,0 +1,12 @@ +fn test() { + let v: isize; + //~^ HELP consider making this binding mutable + //~| SUGGESTION mut v + v = 2; //~ NOTE first assignment + v += 1; //~ ERROR cannot assign twice to immutable variable `v` + //~| NOTE cannot assign twice to immutable + v.clone(); +} + +fn main() { +} diff --git a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-op-eq.stderr b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-op-eq.stderr new file mode 100644 index 000000000..5db9539cb --- /dev/null +++ b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-in-op-eq.stderr @@ -0,0 +1,14 @@ +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: consider making this binding mutable: `mut v` +... +LL | v = 2; + | ----- first assignment to `v` +LL | v += 1; + | ^^^^^^ cannot assign twice to immutable variable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0384`. diff --git a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.rs b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.rs new file mode 100644 index 000000000..c9b16e439 --- /dev/null +++ b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.rs @@ -0,0 +1,12 @@ +fn test() { + let b = Box::new(1); //~ NOTE first assignment + //~| HELP consider making this binding mutable + //~| SUGGESTION mut b + drop(b); + b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b` + //~| NOTE cannot assign twice to immutable + drop(b); +} + +fn main() { +} diff --git a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.stderr b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.stderr new file mode 100644 index 000000000..bb7e7e27a --- /dev/null +++ b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.stderr @@ -0,0 +1,15 @@ +error[E0384]: cannot assign twice to immutable variable `b` + --> $DIR/liveness-assign-imm-local-with-drop.rs:6:5 + | +LL | let b = Box::new(1); + | - + | | + | first assignment to `b` + | help: consider making this binding mutable: `mut b` +... +LL | b = Box::new(2); + | ^ cannot assign twice to immutable variable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0384`. diff --git a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-init.rs b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-init.rs new file mode 100644 index 000000000..4bb2db27a --- /dev/null +++ b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-init.rs @@ -0,0 +1,12 @@ +fn test() { + let v: isize = 1; //~ NOTE first assignment + //~| HELP consider making this binding mutable + //~| SUGGESTION mut v + v.clone(); + v = 2; //~ ERROR cannot assign twice to immutable variable `v` + //~| NOTE cannot assign twice to immutable + v.clone(); +} + +fn main() { +} diff --git a/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-init.stderr b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-init.stderr new file mode 100644 index 000000000..80458a70a --- /dev/null +++ b/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-init.stderr @@ -0,0 +1,15 @@ +error[E0384]: cannot assign twice to immutable variable `v` + --> $DIR/liveness-assign-imm-local-with-init.rs:6:5 + | +LL | let v: isize = 1; + | - + | | + | first assignment to `v` + | help: consider making this binding mutable: `mut v` +... +LL | v = 2; + | ^^^^^ cannot assign twice to immutable variable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0384`. |