]>
Commit | Line | Data |
---|---|---|
2c00a5a8 XL |
1 | // Test that assignments to an `&mut` pointer which is found in a |
2 | // borrowed (but otherwise non-aliasable) location is illegal. | |
3 | ||
48663c56 | 4 | // compile-flags: -C overflow-checks=on |
2c00a5a8 XL |
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; | |
48663c56 XL |
21 | //~^ ERROR cannot use `*y.pointer` because it was mutably borrowed [E0503] |
22 | //~| ERROR cannot assign to `*y.pointer` because it is borrowed [E0506] | |
2c00a5a8 XL |
23 | *z.pointer += 1; |
24 | } | |
25 | } |