about summary refs log tree commit diff
path: root/src/tools/miri/tests/fail/both_borrows/aliasing_mut1.rs
blob: a9efe17fddfabe1fee83d2b5f5886d1482b6950c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//@revisions: stack tree
//@[tree]compile-flags: -Zmiri-tree-borrows
use std::mem;

pub fn safe(x: &mut i32, y: &mut i32) {
    //~[stack]^ ERROR: protect
    *x = 1; //~[tree] ERROR: /write access through .* is forbidden/
    *y = 2;
}

fn main() {
    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).
    let safe_raw: fn(x: *mut i32, y: *mut i32) =
        unsafe { mem::transmute::<fn(&mut i32, &mut i32), _>(safe) };
    safe_raw(xraw, xraw);
}