2018-10-28 23:09:32 -05:00
|
|
|
// issue-49296: Unsafe shenigans in constants can result in missing errors
|
|
|
|
|
|
|
|
#![feature(const_fn_union)]
|
2021-04-18 11:36:41 -05:00
|
|
|
#![feature(const_fn_trait_bound)]
|
2018-10-28 23:09:32 -05:00
|
|
|
|
|
|
|
const unsafe fn transmute<T: Copy, U: Copy>(t: T) -> U {
|
2019-08-30 02:35:02 -05:00
|
|
|
#[repr(C)]
|
2018-10-28 23:09:32 -05:00
|
|
|
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
|
2021-01-30 07:49:22 -06:00
|
|
|
//~| WARN this was previously accepted by the compiler but is being phased out
|
2018-10-28 23:09:32 -05:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
println!("{}", X);
|
|
|
|
}
|