]> git.lizzy.rs Git - rust.git/blob - src/test/ui/regions/regions-reborrow-from-shorter-mut-ref.rs
Rollup merge of #57132 - daxpedda:master, r=steveklabnik
[rust.git] / src / test / ui / regions / regions-reborrow-from-shorter-mut-ref.rs
1 // Issue #8624. Tests that reborrowing the contents of an `&'b mut`
2 // pointer which is backed by another `&'a mut` can only be done
3 // for `'a` (which must be a sublifetime of `'b`).
4
5 fn copy_borrowed_ptr<'a, 'b>(p: &'a mut &'b mut isize) -> &'b mut isize {
6     &mut **p //~ ERROR lifetime mismatch [E0623]
7 }
8
9 fn main() {
10     let mut x = 1;
11     let mut y = &mut x;
12     let z = copy_borrowed_ptr(&mut y);
13     *y += 1;
14     *z += 1;
15 }