]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/two-phase-cannot-nest-mut-self-calls.rs
Merge commit '2ca58e7dda4a9eb142599638c59dc04d15961175' into clippyup
[rust.git] / src / test / ui / borrowck / two-phase-cannot-nest-mut-self-calls.rs
1 // compile-flags: -Z borrowck=mir
2
3 // This is the third counter-example from Niko's blog post
4 // smallcultfollowing.com/babysteps/blog/2017/03/01/nested-method-calls-via-two-phase-borrowing/
5 //
6 // It shows that not all nested method calls on `self` are magically
7 // allowed by this change. In particular, a nested `&mut` borrow is
8 // still disallowed.
9
10 fn main() {
11
12
13     let mut vec = vec![0, 1];
14     vec.get({
15
16         vec.push(2);
17         //~^ ERROR cannot borrow `vec` as mutable because it is also borrowed as immutable
18
19         0
20     });
21 }