summary refs log tree commit diff
path: root/src/test/ui/consts/const-eval/issue-49296.rs
blob: c6caeeffd22dd05bc96455d79da9067cff6d8aab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// issue-49296: Unsafe shenigans in constants can result in missing errors

#![feature(const_fn)]
#![feature(const_fn_union)]

const unsafe fn transmute<T: Copy, U: Copy>(t: T) -> U {
    #[repr(C)]
    union Transmute<T: Copy, U: Copy> {
        from: T,
        to: U,
    }

    Transmute { from: t }.to
}

const fn wat(x: u64) -> &'static u64 {
    unsafe { transmute(&x) }
}
const X: u64 = *wat(42);
//~^ ERROR any use of this value will cause an error

fn main() {
    println!("{}", X);
}