]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/issue-21232-partial-init-and-erroneous-use.rs
fix merge conflicts
[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 struct D {
12     x: u32,
13     s: S,
14 }
15
16 struct S {
17     y: u32,
18     z: u32,
19 }
20
21
22 impl Drop for D {
23     fn drop(&mut self) { }
24 }
25
26 fn cannot_partially_init_adt_with_drop() {
27     let d: D;
28     d.x = 10;
29     //~^ ERROR assign of possibly uninitialized variable: `d` [E0381]
30 }
31
32 fn cannot_partially_init_mutable_adt_with_drop() {
33     let mut d: D;
34     d.x = 10;
35     //~^ ERROR assign of possibly uninitialized variable: `d` [E0381]
36 }
37
38 fn cannot_partially_reinit_adt_with_drop() {
39     let mut d = D { x: 0, s: S{ y: 0, z: 0 } };
40     drop(d);
41     d.x = 10;
42     //~^ ERROR assign of moved value: `d` [E0382]
43 }
44
45 fn cannot_partially_init_inner_adt_via_outer_with_drop() {
46     let d: D;
47     d.s.y = 20;
48     //~^ ERROR assign to part of possibly uninitialized variable: `d` [E0381]
49 }
50
51 fn cannot_partially_init_inner_adt_via_mutable_outer_with_drop() {
52     let mut d: D;
53     d.s.y = 20;
54     //~^ ERROR assign to part of possibly uninitialized variable: `d` [E0381]
55 }
56
57 fn cannot_partially_reinit_inner_adt_via_outer_with_drop() {
58     let mut d = D { x: 0, s: S{ y: 0, z: 0} };
59     drop(d);
60     d.s.y = 20;
61     //~^ ERROR assign to part of moved value: `d` [E0382]
62 }
63
64 fn main() { }