summaryrefslogtreecommitdiffstats
path: root/tests/ui/nll/issue-45157.rs
blob: 8d2bf22a03c9abe416a121b7d6b8b307b848c2bf (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
#![allow(unused)]


#[derive(Clone, Copy, Default)]
struct S {
    a: u8,
    b: u8,
}
#[derive(Clone, Copy, Default)]
struct Z {
    c: u8,
    d: u8,
}

union U {
    s: S,
    z: Z,
}

fn main() {
    unsafe {
        let mut u = U { s: Default::default() };

        let mref = &mut u.s.a;
        *mref = 22;

        let nref = &u.z.c;
        //~^ ERROR cannot borrow `u` (via `u.z.c`) as immutable because it is also borrowed as mutable (via `u.s.a`) [E0502]
        println!("{} {}", mref, nref)
    }
}