2018-11-15 12:49:00 -06:00
|
|
|
use std::cell::Cell;
|
2022-06-21 01:40:39 -05:00
|
|
|
use std::mem;
|
2017-08-09 20:01:10 -05:00
|
|
|
|
2018-11-15 12:49:00 -06:00
|
|
|
// Make sure &mut UnsafeCell also is exclusive
|
2019-04-17 07:57:13 -05:00
|
|
|
pub fn safe(_x: &i32, _y: &mut Cell<i32>) {} //~ ERROR protect
|
2017-08-09 20:01:10 -05:00
|
|
|
|
|
|
|
fn main() {
|
2018-11-15 12:49:00 -06:00
|
|
|
let mut x = 0;
|
|
|
|
let xref = &mut x;
|
|
|
|
let xraw: *mut i32 = unsafe { mem::transmute_copy(&xref) };
|
|
|
|
let xshr = &*xref;
|
|
|
|
// transmute fn ptr around so that we can avoid retagging
|
2022-06-21 01:40:39 -05:00
|
|
|
let safe_raw: fn(x: *const i32, y: *mut Cell<i32>) =
|
|
|
|
unsafe { mem::transmute::<fn(&i32, &mut Cell<i32>), _>(safe) };
|
2018-11-15 12:49:00 -06:00
|
|
|
safe_raw(xshr, xraw as *mut _);
|
2017-08-09 20:01:10 -05:00
|
|
|
}
|