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