]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/stacked_borrows/aliasing_mut1.rs
Rollup merge of #98391 - joboet:sgx_parker, r=m-ou-se
[rust.git] / src / tools / miri / tests / fail / stacked_borrows / aliasing_mut1.rs
1 use std::mem;
2
3 pub fn safe(_x: &mut i32, _y: &mut i32) {} //~ ERROR: protect
4
5 fn main() {
6     let mut x = 0;
7     let xraw: *mut i32 = unsafe { mem::transmute(&mut x) };
8     // We need to apply some tricky to be able to call `safe` with two mutable references
9     // with the same tag: We transmute both the fn ptr (to take raw ptrs) and the argument
10     // (to be raw, but still have the unique tag).
11     let safe_raw: fn(x: *mut i32, y: *mut i32) =
12         unsafe { mem::transmute::<fn(&mut i32, &mut i32), _>(safe) };
13     safe_raw(xraw, xraw);
14 }