diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2018-08-14 08:24:44 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2018-08-19 08:15:13 -0700 |
| commit | 58e4b54bd49a2a554ee8a573827b9ccbf7a9b65e (patch) | |
| tree | 6dc9383f0c27191e7692637f66ca852df11c77be /src/test/ui/borrowck | |
| parent | 4e50c5b6e45fc1b21b0e0bd6f7c9c5389e0b637f (diff) | |
| download | rust-58e4b54bd49a2a554ee8a573827b9ccbf7a9b65e.tar.gz rust-58e4b54bd49a2a554ee8a573827b9ccbf7a9b65e.zip | |
move tests to borrowck directory, remove feature(nll)
now compare-mode can show us the differences
Diffstat (limited to 'src/test/ui/borrowck')
12 files changed, 361 insertions, 0 deletions
diff --git a/src/test/ui/borrowck/assign_mutable_fields.nll.stderr b/src/test/ui/borrowck/assign_mutable_fields.nll.stderr new file mode 100644 index 00000000000..51470753472 --- /dev/null +++ b/src/test/ui/borrowck/assign_mutable_fields.nll.stderr @@ -0,0 +1,9 @@ +error[E0381]: use of possibly uninitialized variable: `x` + --> $DIR/assign_mutable_fields.rs:29:10 + | +LL | drop(x); //~ ERROR + | ^ use of possibly uninitialized `x` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0381`. diff --git a/src/test/ui/borrowck/assign_mutable_fields.rs b/src/test/ui/borrowck/assign_mutable_fields.rs new file mode 100644 index 00000000000..4e41f44ef5b --- /dev/null +++ b/src/test/ui/borrowck/assign_mutable_fields.rs @@ -0,0 +1,32 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Currently, we permit you to assign to individual fields of a mut +// var, but we do not permit you to use the complete var afterwards. +// We hope to fix this at some point. +// +// FIXME(#21232) + +fn assign_both_fields_and_use() { + let mut x: (u32, u32); + x.0 = 1; + x.1 = 22; + drop(x.0); //~ ERROR + drop(x.1); //~ ERROR +} + +fn assign_both_fields_the_use_var() { + let mut x: (u32, u32); + x.0 = 1; + x.1 = 22; + drop(x); //~ ERROR +} + +fn main() { } diff --git a/src/test/ui/borrowck/assign_mutable_fields.stderr b/src/test/ui/borrowck/assign_mutable_fields.stderr new file mode 100644 index 00000000000..677887babd0 --- /dev/null +++ b/src/test/ui/borrowck/assign_mutable_fields.stderr @@ -0,0 +1,21 @@ +error[E0381]: use of possibly uninitialized variable: `x.0` + --> $DIR/assign_mutable_fields.rs:21:10 + | +LL | drop(x.0); //~ ERROR + | ^^^ use of possibly uninitialized `x.0` + +error[E0381]: use of possibly uninitialized variable: `x.1` + --> $DIR/assign_mutable_fields.rs:22:10 + | +LL | drop(x.1); //~ ERROR + | ^^^ use of possibly uninitialized `x.1` + +error[E0381]: use of possibly uninitialized variable: `x` + --> $DIR/assign_mutable_fields.rs:29:10 + | +LL | drop(x); //~ ERROR + | ^ use of possibly uninitialized `x` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0381`. diff --git a/src/test/ui/borrowck/reassignment_immutable_fields.nll.stderr b/src/test/ui/borrowck/reassignment_immutable_fields.nll.stderr new file mode 100644 index 00000000000..97f3bf5b81f --- /dev/null +++ b/src/test/ui/borrowck/reassignment_immutable_fields.nll.stderr @@ -0,0 +1,44 @@ +error[E0594]: cannot assign to `x.0`, as `x` is not declared as mutable + --> $DIR/reassignment_immutable_fields.rs:17:5 + | +LL | let x: (u32, u32); + | - help: consider changing this to be mutable: `mut x` +LL | x.0 = 1; //~ ERROR + | ^^^^^^^ cannot assign + +error[E0594]: cannot assign to `x.1`, as `x` is not declared as mutable + --> $DIR/reassignment_immutable_fields.rs:18:5 + | +LL | let x: (u32, u32); + | - help: consider changing this to be mutable: `mut x` +LL | x.0 = 1; //~ ERROR +LL | x.1 = 22; //~ ERROR + | ^^^^^^^^ cannot assign + +error[E0594]: cannot assign to `x.0`, as `x` is not declared as mutable + --> $DIR/reassignment_immutable_fields.rs:25:5 + | +LL | let x: (u32, u32); + | - help: consider changing this to be mutable: `mut x` +LL | x.0 = 1; //~ ERROR + | ^^^^^^^ cannot assign + +error[E0594]: cannot assign to `x.1`, as `x` is not declared as mutable + --> $DIR/reassignment_immutable_fields.rs:26:5 + | +LL | let x: (u32, u32); + | - help: consider changing this to be mutable: `mut x` +LL | x.0 = 1; //~ ERROR +LL | x.1 = 22; //~ ERROR + | ^^^^^^^^ cannot assign + +error[E0381]: use of possibly uninitialized variable: `x` + --> $DIR/reassignment_immutable_fields.rs:27:10 + | +LL | drop(x); //~ ERROR + | ^ use of possibly uninitialized `x` + +error: aborting due to 5 previous errors + +Some errors occurred: E0381, E0594. +For more information about an error, try `rustc --explain E0381`. diff --git a/src/test/ui/borrowck/reassignment_immutable_fields.rs b/src/test/ui/borrowck/reassignment_immutable_fields.rs new file mode 100644 index 00000000000..c49ae2f9567 --- /dev/null +++ b/src/test/ui/borrowck/reassignment_immutable_fields.rs @@ -0,0 +1,30 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// This test is currently disallowed, but we hope someday to support it. +// +// FIXME(#21232) + +fn assign_both_fields_and_use() { + let x: (u32, u32); + x.0 = 1; //~ ERROR + x.1 = 22; //~ ERROR + drop(x.0); //~ ERROR + drop(x.1); //~ ERROR +} + +fn assign_both_fields_the_use_var() { + let x: (u32, u32); + x.0 = 1; //~ ERROR + x.1 = 22; //~ ERROR + drop(x); //~ ERROR +} + +fn main() { } diff --git a/src/test/ui/borrowck/reassignment_immutable_fields.stderr b/src/test/ui/borrowck/reassignment_immutable_fields.stderr new file mode 100644 index 00000000000..54d12f8fae8 --- /dev/null +++ b/src/test/ui/borrowck/reassignment_immutable_fields.stderr @@ -0,0 +1,56 @@ +error[E0594]: cannot assign to field `x.0` of immutable binding + --> $DIR/reassignment_immutable_fields.rs:17:5 + | +LL | let x: (u32, u32); + | - consider changing this to `mut x` +LL | x.0 = 1; //~ ERROR + | ^^^^^^^ cannot mutably borrow field of immutable binding + +error[E0594]: cannot assign to field `x.1` of immutable binding + --> $DIR/reassignment_immutable_fields.rs:18:5 + | +LL | let x: (u32, u32); + | - consider changing this to `mut x` +LL | x.0 = 1; //~ ERROR +LL | x.1 = 22; //~ ERROR + | ^^^^^^^^ cannot mutably borrow field of immutable binding + +error[E0381]: use of possibly uninitialized variable: `x.0` + --> $DIR/reassignment_immutable_fields.rs:19:10 + | +LL | drop(x.0); //~ ERROR + | ^^^ use of possibly uninitialized `x.0` + +error[E0381]: use of possibly uninitialized variable: `x.1` + --> $DIR/reassignment_immutable_fields.rs:20:10 + | +LL | drop(x.1); //~ ERROR + | ^^^ use of possibly uninitialized `x.1` + +error[E0594]: cannot assign to field `x.0` of immutable binding + --> $DIR/reassignment_immutable_fields.rs:25:5 + | +LL | let x: (u32, u32); + | - consider changing this to `mut x` +LL | x.0 = 1; //~ ERROR + | ^^^^^^^ cannot mutably borrow field of immutable binding + +error[E0594]: cannot assign to field `x.1` of immutable binding + --> $DIR/reassignment_immutable_fields.rs:26:5 + | +LL | let x: (u32, u32); + | - consider changing this to `mut x` +LL | x.0 = 1; //~ ERROR +LL | x.1 = 22; //~ ERROR + | ^^^^^^^^ cannot mutably borrow field of immutable binding + +error[E0381]: use of possibly uninitialized variable: `x` + --> $DIR/reassignment_immutable_fields.rs:27:10 + | +LL | drop(x); //~ ERROR + | ^ use of possibly uninitialized `x` + +error: aborting due to 7 previous errors + +Some errors occurred: E0381, E0594. +For more information about an error, try `rustc --explain E0381`. diff --git a/src/test/ui/borrowck/reassignment_immutable_fields_overlapping.nll.stderr b/src/test/ui/borrowck/reassignment_immutable_fields_overlapping.nll.stderr new file mode 100644 index 00000000000..c433d6e25c9 --- /dev/null +++ b/src/test/ui/borrowck/reassignment_immutable_fields_overlapping.nll.stderr @@ -0,0 +1,20 @@ +error[E0594]: cannot assign to `x.a`, as `x` is not declared as mutable + --> $DIR/reassignment_immutable_fields_overlapping.rs:22:5 + | +LL | let x: Foo; + | - help: consider changing this to be mutable: `mut x` +LL | x.a = 1; //~ ERROR + | ^^^^^^^ cannot assign + +error[E0594]: cannot assign to `x.b`, as `x` is not declared as mutable + --> $DIR/reassignment_immutable_fields_overlapping.rs:23:5 + | +LL | let x: Foo; + | - help: consider changing this to be mutable: `mut x` +LL | x.a = 1; //~ ERROR +LL | x.b = 22; //~ ERROR + | ^^^^^^^^ cannot assign + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/borrowck/reassignment_immutable_fields_overlapping.rs b/src/test/ui/borrowck/reassignment_immutable_fields_overlapping.rs new file mode 100644 index 00000000000..add23ec8f24 --- /dev/null +++ b/src/test/ui/borrowck/reassignment_immutable_fields_overlapping.rs @@ -0,0 +1,26 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// This should never be allowed -- `foo.a` and `foo.b` are +// overlapping, so since `x` is not `mut` we should not permit +// reassignment. + +union Foo { + a: u32, + b: u32, +} + +unsafe fn overlapping_fields() { + let x: Foo; + x.a = 1; //~ ERROR + x.b = 22; //~ ERROR +} + +fn main() { } diff --git a/src/test/ui/borrowck/reassignment_immutable_fields_overlapping.stderr b/src/test/ui/borrowck/reassignment_immutable_fields_overlapping.stderr new file mode 100644 index 00000000000..70849905f92 --- /dev/null +++ b/src/test/ui/borrowck/reassignment_immutable_fields_overlapping.stderr @@ -0,0 +1,20 @@ +error[E0594]: cannot assign to field `x.a` of immutable binding + --> $DIR/reassignment_immutable_fields_overlapping.rs:22:5 + | +LL | let x: Foo; + | - consider changing this to `mut x` +LL | x.a = 1; //~ ERROR + | ^^^^^^^ cannot mutably borrow field of immutable binding + +error[E0594]: cannot assign to field `x.b` of immutable binding + --> $DIR/reassignment_immutable_fields_overlapping.rs:23:5 + | +LL | let x: Foo; + | - consider changing this to `mut x` +LL | x.a = 1; //~ ERROR +LL | x.b = 22; //~ ERROR + | ^^^^^^^^ cannot mutably borrow field of immutable binding + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/borrowck/reassignment_immutable_fields_twice.nll.stderr b/src/test/ui/borrowck/reassignment_immutable_fields_twice.nll.stderr new file mode 100644 index 00000000000..2160ae20c42 --- /dev/null +++ b/src/test/ui/borrowck/reassignment_immutable_fields_twice.nll.stderr @@ -0,0 +1,38 @@ +error[E0594]: cannot assign to `x.0`, as `x` is not declared as mutable + --> $DIR/reassignment_immutable_fields_twice.rs:17:5 + | +LL | let x: (u32, u32); + | - help: consider changing this to be mutable: `mut x` +LL | x = (22, 44); +LL | x.0 = 1; //~ ERROR + | ^^^^^^^ cannot assign + +error[E0594]: cannot assign to `x.0`, as `x` is not declared as mutable + --> $DIR/reassignment_immutable_fields_twice.rs:22:5 + | +LL | let x: (u32, u32); + | - help: consider changing this to be mutable: `mut x` +LL | x.0 = 1; //~ ERROR + | ^^^^^^^ cannot assign + +error[E0594]: cannot assign to `x.0`, as `x` is not declared as mutable + --> $DIR/reassignment_immutable_fields_twice.rs:23:5 + | +LL | let x: (u32, u32); + | - help: consider changing this to be mutable: `mut x` +LL | x.0 = 1; //~ ERROR +LL | x.0 = 22; //~ ERROR + | ^^^^^^^^ cannot assign + +error[E0594]: cannot assign to `x.1`, as `x` is not declared as mutable + --> $DIR/reassignment_immutable_fields_twice.rs:24:5 + | +LL | let x: (u32, u32); + | - help: consider changing this to be mutable: `mut x` +... +LL | x.1 = 44; //~ ERROR + | ^^^^^^^^ cannot assign + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0594`. diff --git a/src/test/ui/borrowck/reassignment_immutable_fields_twice.rs b/src/test/ui/borrowck/reassignment_immutable_fields_twice.rs new file mode 100644 index 00000000000..c7e7e5c4533 --- /dev/null +++ b/src/test/ui/borrowck/reassignment_immutable_fields_twice.rs @@ -0,0 +1,27 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// This should never be allowed -- since `x` is not `mut`, so `x.0` +// cannot be assigned twice. + +fn var_then_field() { + let x: (u32, u32); + x = (22, 44); + x.0 = 1; //~ ERROR +} + +fn same_field_twice() { + let x: (u32, u32); + x.0 = 1; //~ ERROR + x.0 = 22; //~ ERROR + x.1 = 44; //~ ERROR +} + +fn main() { } diff --git a/src/test/ui/borrowck/reassignment_immutable_fields_twice.stderr b/src/test/ui/borrowck/reassignment_immutable_fields_twice.stderr new file mode 100644 index 00000000000..b3c013d8b1f --- /dev/null +++ b/src/test/ui/borrowck/reassignment_immutable_fields_twice.stderr @@ -0,0 +1,38 @@ +error[E0594]: cannot assign to field `x.0` of immutable binding + --> $DIR/reassignment_immutable_fields_twice.rs:17:5 + | +LL | let x: (u32, u32); + | - consider changing this to `mut x` +LL | x = (22, 44); +LL | x.0 = 1; //~ ERROR + | ^^^^^^^ cannot mutably borrow field of immutable binding + +error[E0594]: cannot assign to field `x.0` of immutable binding + --> $DIR/reassignment_immutable_fields_twice.rs:22:5 + | +LL | let x: (u32, u32); + | - consider changing this to `mut x` +LL | x.0 = 1; //~ ERROR + | ^^^^^^^ cannot mutably borrow field of immutable binding + +error[E0594]: cannot assign to field `x.0` of immutable binding + --> $DIR/reassignment_immutable_fields_twice.rs:23:5 + | +LL | let x: (u32, u32); + | - consider changing this to `mut x` +LL | x.0 = 1; //~ ERROR +LL | x.0 = 22; //~ ERROR + | ^^^^^^^^ cannot mutably borrow field of immutable binding + +error[E0594]: cannot assign to field `x.1` of immutable binding + --> $DIR/reassignment_immutable_fields_twice.rs:24:5 + | +LL | let x: (u32, u32); + | - consider changing this to `mut x` +... +LL | x.1 = 44; //~ ERROR + | ^^^^^^^^ cannot mutably borrow field of immutable binding + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0594`. |
