]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-union-move-assign.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / borrowck-union-move-assign.rs
1 use std::mem::ManuallyDrop;
2
3 // Non-copy
4 struct A;
5 struct B;
6
7 union U {
8     a: ManuallyDrop<A>,
9     b: ManuallyDrop<B>,
10 }
11
12 fn main() {
13     unsafe {
14         {
15             let mut u = U { a: ManuallyDrop::new(A) };
16             let a = u.a;
17             let a = u.a; //~ ERROR use of moved value: `u`
18         }
19         {
20             let mut u = U { a: ManuallyDrop::new(A) };
21             let a = u.a;
22             u.a = ManuallyDrop::new(A);
23             let a = u.a; // OK
24         }
25         {
26             let mut u = U { a: ManuallyDrop::new(A) };
27             let a = u.a;
28             u.b = ManuallyDrop::new(B);
29             let a = u.a; // OK
30         }
31     }
32 }