about summary refs log tree commit diff
path: root/src/tools/miri/tests/pass/option_box_transmute_ptr.rs
blob: 0ba6607a5d442ff640f9608efd7125f4958fd17b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//@revisions: stack tree
//@[tree]compile-flags: -Zmiri-tree-borrows
// This tests that the size of Option<Box<i32>> is the same as *const i32.
fn option_box_deref() -> i32 {
    let val = Some(Box::new(42));
    unsafe {
        let ptr: *const i32 = std::mem::transmute::<Option<Box<i32>>, *const i32>(val);
        let ret = *ptr;
        // unleak memory
        std::mem::transmute::<*const i32, Option<Box<i32>>>(ptr);
        ret
    }
}

fn main() {
    assert_eq!(option_box_deref(), 42);
}