Auto merge of #2050 - RalfJung:partially-uninit, r=RalfJung

test that partially uninit MaybeUninit works correctly

This got finally fixed by https://github.com/rust-lang/rust/pull/94527 :)
This commit is contained in:
bors 2022-04-05 22:31:24 +00:00
commit fb01df538e
2 changed files with 16 additions and 1 deletions

View File

@ -1 +1 @@
634770c0a7f8598164ab825cfe419cc8b03c36e5
f262ca12aac76152c4b46cefcf8300f0249a5eb2

View File

@ -0,0 +1,15 @@
// compile-flags: -Zmiri-check-number-validity
use std::mem::{self, MaybeUninit};
#[repr(C)]
#[derive(Copy, Clone, Debug, PartialEq)]
struct Demo(bool, u16);
fn main() { unsafe {
// Transmute-round-trip through a type with Scalar layout is lossless.
// This is tricky because that 'scalar' is *partially* uninitialized.
let x = Demo(true, 3);
let y: MaybeUninit<u32> = mem::transmute(x);
assert_eq!(x, mem::transmute(y));
} }