]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/tests/fail/stacked_borrows/alias_through_mutation.rs
Rollup merge of #102085 - chenyukang:code-refactor, r=cjgillot
[rust.git] / src / tools / miri / tests / fail / stacked_borrows / alias_through_mutation.rs
1 // This makes a ref that was passed to us via &mut alias with things it should not alias with
2 fn retarget(x: &mut &u32, target: &mut u32) {
3     unsafe {
4         *x = &mut *(target as *mut _);
5     }
6 }
7
8 fn main() {
9     let target = &mut 42;
10     let mut target_alias = &42; // initial dummy value
11     retarget(&mut target_alias, target);
12     // now `target_alias` points to the same thing as `target`
13     *target = 13;
14     let _val = *target_alias; //~ ERROR: /read access .* tag does not exist in the borrow stack/
15 }