rust/tests/pass/issues/issue-miri-2068-2.rs
2022-07-08 16:08:32 +00:00

17 lines
491 B
Rust

//@compile-flags: -Zmiri-disable-validation
use std::mem::MaybeUninit;
fn main() {
unsafe {
let mut x = MaybeUninit::<i64>::uninit();
// Put in a ptr.
x.as_mut_ptr().cast::<&i32>().write_unaligned(&0);
// Overwrite parts of that pointer with 'uninit' through a Scalar.
let ptr = x.as_mut_ptr().cast::<i32>();
*ptr = MaybeUninit::uninit().assume_init();
// Reading this back should hence work fine.
let _c = *ptr;
}
}