rust/tests/fail/const-ub-checks.rs

12 lines
237 B
Rust
Raw Normal View History

2022-08-13 07:22:19 -05:00
#![feature(const_ptr_read)]
const UNALIGNED_READ: () = unsafe {
let x = &[0u8; 4];
let ptr = x.as_ptr().cast::<u32>();
ptr.read(); //~ERROR: evaluation of constant value failed
};
fn main() {
let _x = UNALIGNED_READ;
}