]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/issue-21232-partial-init-and-erroneous-use.rs
Rollup merge of #60685 - dtolnay:spdx, r=nikomatsakis
[rust.git] / src / test / ui / nll / issue-21232-partial-init-and-erroneous-use.rs
1 // This test enumerates various cases of interest where a ADT or tuple is
2 // partially initialized and then used in some way that is wrong *even*
3 // after rust-lang/rust#54987 is implemented.
4 //
5 // See rust-lang/rust#21232, rust-lang/rust#54986, and rust-lang/rust#54987.
6 //
7 // See issue-21232-partial-init-and-use.rs for cases of tests that are
8 // meant to compile and run successfully once rust-lang/rust#54987 is
9 // implemented.
10
11 #![feature(nll)]
12
13 struct D {
14     x: u32,
15     s: S,
16 }
17
18 struct S {
19     y: u32,
20     z: u32,
21 }
22
23
24 impl Drop for D {
25     fn drop(&mut self) { }
26 }
27
28 fn cannot_partially_init_adt_with_drop() {
29     let d: D;
30     d.x = 10;
31     //~^ ERROR assign of possibly uninitialized variable: `d` [E0381]
32 }
33
34 fn cannot_partially_init_mutable_adt_with_drop() {
35     let mut d: D;
36     d.x = 10;
37     //~^ ERROR assign of possibly uninitialized variable: `d` [E0381]
38 }
39
40 fn cannot_partially_reinit_adt_with_drop() {
41     let mut d = D { x: 0, s: S{ y: 0, z: 0 } };
42     drop(d);
43     d.x = 10;
44     //~^ ERROR assign of moved value: `d` [E0382]
45 }
46
47 fn cannot_partially_init_inner_adt_via_outer_with_drop() {
48     let d: D;
49     d.s.y = 20;
50     //~^ ERROR assign to part of possibly uninitialized variable: `d` [E0381]
51 }
52
53 fn cannot_partially_init_inner_adt_via_mutable_outer_with_drop() {
54     let mut d: D;
55     d.s.y = 20;
56     //~^ ERROR assign to part of possibly uninitialized variable: `d` [E0381]
57 }
58
59 fn cannot_partially_reinit_inner_adt_via_outer_with_drop() {
60     let mut d = D { x: 0, s: S{ y: 0, z: 0} };
61     drop(d);
62     d.s.y = 20;
63     //~^ ERROR assign to part of moved value: `d` [E0382]
64 }
65
66 fn main() { }