2020-02-24 16:22:02 +01:00
|
|
|
// Stacked Borrows disallows this becuase the reference is never cast to a raw pointer.
|
2022-06-06 11:44:36 -04:00
|
|
|
// compile-flags: -Zmiri-disable-stacked-borrows
|
2019-07-03 10:19:55 +02:00
|
|
|
|
2018-08-14 18:51:15 +02:00
|
|
|
fn main() {
|
|
|
|
// If we are careful, we can exploit data layout...
|
|
|
|
let raw = unsafe {
|
2022-06-06 11:44:36 -04:00
|
|
|
std::mem::transmute::<&[u8], [*const u8; 2]>(&[42])
|
2018-08-14 18:51:15 +02:00
|
|
|
};
|
2022-06-06 11:44:36 -04:00
|
|
|
let ptr: *const u8 = unsafe { std::mem::transmute_copy(&raw) };
|
|
|
|
assert_eq!(unsafe { *ptr }, 42);
|
2018-08-14 18:51:15 +02:00
|
|
|
}
|