]> git.lizzy.rs Git - rust.git/blob - tests/compile-fail/stacked_borrows/alias_through_mutation.rs
adjust compile-fail error messages
[rust.git] / tests / compile-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 { *x = &mut *(target as *mut _); }
4 }
5
6 fn main() {
7     let target = &mut 42;
8     let mut target_alias = &42; // initial dummy value
9     retarget(&mut target_alias, target);
10     // now `target_alias` points to the same thing as `target`
11     *target = 13;
12     let _val = *target_alias; //~ ERROR borrow stack
13 }