]> git.proxmox.com Git - rustc.git/blob - src/test/ui/consts/const-eval/ub-uninhabit.rs
New upstream version 1.53.0+dfsg1
[rustc.git] / src / test / ui / consts / const-eval / ub-uninhabit.rs
1 // stderr-per-bitwidth
2 #![allow(const_err)] // make sure we cannot allow away the errors tested here
3
4 use std::mem;
5
6 #[derive(Copy, Clone)]
7 enum Bar {}
8
9 #[repr(C)]
10 union MaybeUninit<T: Copy> {
11 uninit: (),
12 init: T,
13 }
14
15 const BAD_BAD_BAD: Bar = unsafe { MaybeUninit { uninit: () }.init };
16 //~^ ERROR it is undefined behavior to use this value
17
18 const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) };
19 //~^ ERROR it is undefined behavior to use this value
20
21 const BAD_BAD_ARRAY: [Bar; 1] = unsafe { MaybeUninit { uninit: () }.init };
22 //~^ ERROR it is undefined behavior to use this value
23
24 fn main() {}