summaryrefslogtreecommitdiffstats
path: root/tests/ui/borrowck/borrowck-union-move-assign.rs
blob: 4c96ccdb25aaa36db21841a5cf9448cede5ccc04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::mem::ManuallyDrop;

// Non-copy
struct A;
struct B;

union U {
    a: ManuallyDrop<A>,
    b: ManuallyDrop<B>,
}

fn main() {
    unsafe {
        {
            let mut u = U { a: ManuallyDrop::new(A) };
            let a = u.a;
            let a = u.a; //~ ERROR use of moved value: `u`
        }
        {
            let mut u = U { a: ManuallyDrop::new(A) };
            let a = u.a;
            u.a = ManuallyDrop::new(A);
            let a = u.a; // OK
        }
        {
            let mut u = U { a: ManuallyDrop::new(A) };
            let a = u.a;
            u.b = ManuallyDrop::new(B);
            let a = u.a; // OK
        }
    }
}