]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-eval/issue-49296.rs
Auto merge of #81132 - bugadani:map-prealloc, r=matthewjasper
[rust.git] / src / test / ui / consts / const-eval / issue-49296.rs
1 // issue-49296: Unsafe shenigans in constants can result in missing errors
2
3 #![feature(const_fn)]
4 #![feature(const_fn_union)]
5
6 const unsafe fn transmute<T: Copy, U: Copy>(t: T) -> U {
7     #[repr(C)]
8     union Transmute<T: Copy, U: Copy> {
9         from: T,
10         to: U,
11     }
12
13     Transmute { from: t }.to
14 }
15
16 const fn wat(x: u64) -> &'static u64 {
17     unsafe { transmute(&x) }
18 }
19 const X: u64 = *wat(42);
20 //~^ ERROR any use of this value will cause an error
21 //~| WARN this was previously accepted by the compiler but is being phased out
22
23 fn main() {
24     println!("{}", X);
25 }