]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/pass/option_box_transmute_ptr.rs
Auto merge of #104915 - weihanglo:update-cargo, r=ehuss
[rust.git] / src / tools / miri / tests / pass / option_box_transmute_ptr.rs
1 // This tests that the size of Option<Box<i32>> is the same as *const i32.
2 fn option_box_deref() -> i32 {
3     let val = Some(Box::new(42));
4     unsafe {
5         let ptr: *const i32 = std::mem::transmute::<Option<Box<i32>>, *const i32>(val);
6         let ret = *ptr;
7         // unleak memory
8         std::mem::transmute::<*const i32, Option<Box<i32>>>(ptr);
9         ret
10     }
11 }
12
13 fn main() {
14     assert_eq!(option_box_deref(), 42);
15 }