2018-11-15 12:49:00 -06:00
|
|
|
use std::mem;
|
|
|
|
|
2022-07-11 06:44:55 -05:00
|
|
|
pub fn safe(_x: &mut i32, _y: &mut i32) {} //~ ERROR: protect
|
2017-08-07 19:39:09 -05:00
|
|
|
|
|
|
|
fn main() {
|
2018-11-15 12:49:00 -06:00
|
|
|
let mut x = 0;
|
|
|
|
let xraw: *mut i32 = unsafe { mem::transmute(&mut x) };
|
|
|
|
// We need to apply some tricky to be able to call `safe` with two mutable references
|
|
|
|
// with the same tag: We transmute both the fn ptr (to take raw ptrs) and the argument
|
|
|
|
// (to be raw, but still have the unique tag).
|
2022-06-21 01:40:39 -05:00
|
|
|
let safe_raw: fn(x: *mut i32, y: *mut i32) =
|
|
|
|
unsafe { mem::transmute::<fn(&mut i32, &mut i32), _>(safe) };
|
2018-11-15 12:49:00 -06:00
|
|
|
safe_raw(xraw, xraw);
|
2017-08-07 19:39:09 -05:00
|
|
|
}
|