]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/regions-reborrow-from-shorter-mut-ref.rs
399ebd6a2a72620431e4f89abb7a383b014ea8e7
[rust.git] / src / test / compile-fail / regions-reborrow-from-shorter-mut-ref.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Issue #8624. Tests that reborrowing the contents of an `&'b mut`
12 // pointer which is backed by another `&'a mut` can only be done
13 // for `'a` (which must be a sublifetime of `'b`).
14
15 fn copy_borrowed_ptr<'a, 'b>(p: &'a mut &'b mut isize) -> &'b mut isize {
16     &mut **p //~ ERROR cannot infer
17 }
18
19 fn main() {
20     let mut x = 1;
21     let mut y = &mut x;
22     let z = copy_borrowed_ptr(&mut y);
23     *y += 1;
24     *z += 1;
25 }