]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-reborrow-from-shorter-lived-andmut.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / borrowck-reborrow-from-shorter-lived-andmut.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,'b>(p: &'a mut S<'b>) -> S<'b> {
9     S { pointer: &mut *p.pointer }
10     //~^ ERROR lifetime may not live long enough
11 }
12
13 fn main() {
14     let mut x = 1;
15
16     {
17         let mut y = S { pointer: &mut x };
18         let z = copy_borrowed_ptr(&mut y);
19         *y.pointer += 1;
20         *z.pointer += 1;
21     }
22 }