about summary refs log tree commit diff
path: root/src/tools/miri/tests/pass/partially-uninit.rs
blob: db26a2084b1c0cba4e30de72bc72e06cdc89ea4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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));
    }
}