]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-45697.rs
Rollup merge of #91804 - woppopo:const_clone, r=oli-obk
[rust.git] / src / test / ui / issues / issue-45697.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: -C overflow-checks=off
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 use `*y.pointer` because it was mutably borrowed [E0503]
22         //~| ERROR cannot assign to `*y.pointer` because it is borrowed [E0506]
23         *z.pointer += 1;
24     }
25 }