summaryrefslogtreecommitdiffstats
path: root/src/test/ui/consts/const-eval/ub-enum-overwrite.rs
blob: c5677849229c226b26bb8d3d82c31d26df6f57f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#![feature(const_mut_refs)]

enum E {
    A(u8),
    B,
}

const _: u8 = {
    //~^ ERROR is undefined behavior
    let mut e = E::A(1);
    let p = if let E::A(x) = &mut e { x as *mut u8 } else { unreachable!() };
    // Make sure overwriting `e` uninitializes other bytes
    e = E::B;
    unsafe { *p }
};

fn main() {}