2016-04-30 01:04:17 -06:00
|
|
|
// This tests that the size of Option<Box<i32>> is the same as *const i32.
|
2016-04-22 15:04:12 +02:00
|
|
|
fn option_box_deref() -> i32 {
|
|
|
|
let val = Some(Box::new(42));
|
|
|
|
unsafe {
|
2016-04-30 01:04:17 -06:00
|
|
|
let ptr: *const i32 = std::mem::transmute::<Option<Box<i32>>, *const i32>(val);
|
2017-02-14 16:55:30 +01:00
|
|
|
let ret = *ptr;
|
|
|
|
// unleak memory
|
|
|
|
std::mem::transmute::<*const i32, Option<Box<i32>>>(ptr);
|
|
|
|
ret
|
2016-04-22 15:04:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-17 22:52:24 -06:00
|
|
|
fn main() {
|
|
|
|
assert_eq!(option_box_deref(), 42);
|
|
|
|
}
|