]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-45697-1.rs
Remove licenses
[rust.git] / src / test / ui / issues / issue-45697-1.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 // compile-flags: -Z borrowck=compare -C overflow-checks=on
5
6 struct S<'a> {
7     pointer: &'a mut isize
8 }
9
10 fn copy_borrowed_ptr<'a>(p: &'a mut S<'a>) -> S<'a> {
11     S { pointer: &mut *p.pointer }
12 }
13
14 fn main() {
15     let mut x = 1;
16
17     {
18         let mut y = S { pointer: &mut x };
19         let z = copy_borrowed_ptr(&mut y);
20         *y.pointer += 1;
21         //~^ ERROR cannot assign to `*y.pointer` because it is borrowed (Ast) [E0506]
22         //~| ERROR cannot use `*y.pointer` because it was mutably borrowed (Mir) [E0503]
23         //~| ERROR cannot assign to `*y.pointer` because it is borrowed (Mir) [E0506]
24         *z.pointer += 1;
25     }
26 }