]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-eval/ub-uninhabit.rs
Rollup merge of #64038 - matthewjasper:deny-mutual-impl-trait-recursion, r=varkor
[rust.git] / src / test / ui / consts / const-eval / ub-uninhabit.rs
1 #![feature(const_transmute)]
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 TransmuteUnion<A: Clone + Copy, B: Clone + Copy> {
11     a: A,
12     b: B,
13 }
14
15 const BAD_BAD_BAD: Bar = unsafe { (TransmuteUnion::<(), Bar> { a: () }).b };
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 { (TransmuteUnion::<(), [Bar; 1]> { a: () }).b };
22 //~^ ERROR it is undefined behavior to use this value
23
24 fn main() {}