rust/tests/compile-fail-fullmir/stacked_borrows/aliasing_mut4.rs

20 lines
548 B
Rust
Raw Normal View History

#![allow(unused_variables)]
2018-11-15 12:49:00 -06:00
use std::mem;
use std::cell::Cell;
2018-11-15 12:49:00 -06:00
// Make sure &mut UnsafeCell also is exclusive
pub fn safe(x: &i32, y: &mut Cell<i32>) {} //~ ERROR barrier
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
let safe_raw: fn(x: *const i32, y: *mut Cell<i32>) = unsafe {
mem::transmute::<fn(&i32, &mut Cell<i32>), _>(safe)
};
safe_raw(xshr, xraw as *mut _);
}