]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-assign-to-andmut-in-borrowed-loc.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / borrowck-assign-to-andmut-in-borrowed-loc.rs
1 // Test that assignments to an `&mut` pointer which is found in a
2 // borrowed (but otherwise non-aliasable) location is illegal.
3
4 struct S<'a> {
5     pointer: &'a mut isize
6 }
7
8 fn copy_borrowed_ptr<'a>(p: &'a mut S<'a>) -> S<'a> {
9     S { pointer: &mut *p.pointer }
10 }
11
12 fn main() {
13     let mut x = 1;
14
15     {
16         let mut y = S { pointer: &mut x };
17         let z = copy_borrowed_ptr(&mut y);
18         *y.pointer += 1;
19         //~^ ERROR cannot use `*y.pointer`
20         //~| ERROR cannot assign to `*y.pointer`
21         *z.pointer += 1;
22     }
23 }