rust/src/test/ui/consts/const-eval/issue-49296.rs

26 lines
558 B
Rust
Raw Normal View History

2018-10-28 23:09:32 -05:00
// issue-49296: Unsafe shenigans in constants can result in missing errors
#![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 {
#[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);
}