]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/stacked_borrows/aliasing_mut4.rs
Rollup merge of #101774 - Riolku:atomic-update-aba, r=m-ou-se
[rust.git] / src / tools / miri / tests / fail / stacked_borrows / aliasing_mut4.rs
1 use std::cell::Cell;
2 use std::mem;
3
4 // Make sure &mut UnsafeCell also is exclusive
5 pub fn safe(_x: &i32, _y: &mut Cell<i32>) {} //~ ERROR: protect
6
7 fn main() {
8     let mut x = 0;
9     let xref = &mut x;
10     let xraw: *mut i32 = unsafe { mem::transmute_copy(&xref) };
11     let xshr = &*xref;
12     // transmute fn ptr around so that we can avoid retagging
13     let safe_raw: fn(x: *const i32, y: *mut Cell<i32>) =
14         unsafe { mem::transmute::<fn(&i32, &mut Cell<i32>), _>(safe) };
15     safe_raw(xshr, xraw as *mut _);
16 }