]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/transmute-pair-uninit.rs
Rollup merge of #102137 - b-naber:lazy-const-val-conversion, r=lcnr
[rust.git] / src / tools / miri / tests / fail / transmute-pair-uninit.rs
1 #![feature(core_intrinsics)]
2
3 use std::mem;
4
5 fn main() {
6     let x: Option<Box<[u8]>> = unsafe {
7         let z = std::intrinsics::add_with_overflow(0usize, 0usize);
8         std::mem::transmute::<(usize, bool), Option<Box<[u8]>>>(z)
9     };
10     let y = &x;
11     // Now read this bytewise. There should be (`ptr_size + 1`) def bytes followed by
12     // (`ptr_size - 1`) undef bytes (the padding after the bool) in there.
13     let z: *const u8 = y as *const _ as *const _;
14     let first_undef = mem::size_of::<usize>() as isize + 1;
15     for i in 0..first_undef {
16         let byte = unsafe { *z.offset(i) };
17         assert_eq!(byte, 0);
18     }
19     let v = unsafe { *z.offset(first_undef) };
20     //~^ ERROR: uninitialized
21     if v == 0 {
22         println!("it is zero");
23     }
24 }