]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/borrowck/two-phase-allow-access-during-reservation.rs
1 // revisions: nll_target
3 // The following revisions are disabled due to missing support for two_phase_beyond_autoref
4 //[nll_beyond] compile-flags: -Z two_phase_beyond_autoref
6 // This is the second counter-example from Niko's blog post
7 // smallcultfollowing.com/babysteps/blog/2017/03/01/nested-method-calls-via-two-phase-borrowing/
9 // It is "artificial". It is meant to illustrate directly that we
10 // should allow an aliasing access during reservation, but *not* while
11 // the mutable borrow is active.
13 // The convention for the listed revisions: "lxl" means lexical
14 // lifetimes (which can be easier to reason about). "nll" means
15 // non-lexical lifetimes. "nll_target" means the initial conservative
16 // two-phase borrows that only applies to autoref-introduced borrows.
17 // "nll_beyond" means the generalization of two-phase borrows to all
18 // `&mut`-borrows (doing so makes it easier to write code for specific
24 /*1*/ let p
= &mut i
; // (reservation of `i` starts here)
26 /*2*/ let j
= i
; // OK: `i` is only reserved here
27 //[nll_target]~^ ERROR cannot use `i` because it was mutably borrowed [E0503]
29 /*3*/ *p
+= 1; // (mutable borrow of `i` starts here, since `p` is used)
31 /*4*/ let k
= i
; //[nll_beyond]~ ERROR cannot use `i` because it was mutably borrowed [E0503]
32 //[nll_target]~^ ERROR cannot use `i` because it was mutably borrowed [E0503]