]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-union-move.rs
Auto merge of #54624 - arielb1:evaluate-outlives, r=nikomatsakis
[rust.git] / src / test / ui / borrowck / borrowck-union-move.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(untagged_unions)]
12
13 #[derive(Clone, Copy)]
14 struct Copy;
15 struct NonCopy;
16
17 union Unn {
18     n1: NonCopy,
19     n2: NonCopy,
20 }
21 union Ucc {
22     c1: Copy,
23     c2: Copy,
24 }
25 union Ucn {
26     c: Copy,
27     n: NonCopy,
28 }
29
30 fn main() {
31     unsafe {
32         // 2 NonCopy
33         {
34             let mut u = Unn { n1: NonCopy };
35             let a = u.n1;
36             let a = u.n1; //~ ERROR use of moved value: `u.n1`
37         }
38         {
39             let mut u = Unn { n1: NonCopy };
40             let a = u.n1;
41             let a = u; //~ ERROR use of partially moved value: `u`
42         }
43         {
44             let mut u = Unn { n1: NonCopy };
45             let a = u.n1;
46             let a = u.n2; //~ ERROR use of moved value: `u.n2`
47         }
48         // 2 Copy
49         {
50             let mut u = Ucc { c1: Copy };
51             let a = u.c1;
52             let a = u.c1; // OK
53         }
54         {
55             let mut u = Ucc { c1: Copy };
56             let a = u.c1;
57             let a = u; // OK
58         }
59         {
60             let mut u = Ucc { c1: Copy };
61             let a = u.c1;
62             let a = u.c2; // OK
63         }
64         // 1 Copy, 1 NonCopy
65         {
66             let mut u = Ucn { c: Copy };
67             let a = u.c;
68             let a = u.c; // OK
69         }
70         {
71             let mut u = Ucn { c: Copy };
72             let a = u.n;
73             let a = u.n; //~ ERROR use of moved value: `u.n`
74         }
75         {
76             let mut u = Ucn { c: Copy };
77             let a = u.n;
78             let a = u.c; //~ ERROR use of moved value: `u.c`
79         }
80         {
81             let mut u = Ucn { c: Copy };
82             let a = u.c;
83             let a = u.n; // OK
84         }
85         {
86             let mut u = Ucn { c: Copy };
87             let a = u.c;
88             let a = u; // OK
89         }
90         {
91             let mut u = Ucn { c: Copy };
92             let a = u.n;
93             let a = u; //~ ERROR use of partially moved value: `u`
94         }
95     }
96 }