2018-10-28 23:09:32 -05:00
|
|
|
// issue-49296: Unsafe shenigans in constants can result in missing errors
|
|
|
|
|
2021-04-18 11:36:41 -05:00
|
|
|
#![feature(const_fn_trait_bound)]
|
2021-07-25 23:29:18 -05:00
|
|
|
#![feature(const_trait_bound_opt_out)]
|
|
|
|
#![allow(incomplete_features)]
|
2018-10-28 23:09:32 -05:00
|
|
|
|
2021-07-25 23:29:18 -05:00
|
|
|
const unsafe fn transmute<T: ?const Copy, U: ?const 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);
|
2021-06-18 12:31:56 -05:00
|
|
|
//~^ ERROR evaluation of constant value failed
|
2018-10-28 23:09:32 -05:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
println!("{}", X);
|
|
|
|
}
|