1 // revisions: nll_target
3 // The nll_beyond revision is disabled due to missing support from two-phase beyond autorefs
4 //[nll_beyond]compile-flags: -Z borrowck=mir -Z two-phase-beyond-autoref
5 //[nll_beyond]should-fail
7 //[nll_target]compile-flags: -Z borrowck=mir
9 // This is a corner case that the current implementation is (probably)
10 // treating more conservatively than is necessary. But it also does
11 // not seem like a terribly important use case to cover.
13 // So this test is just making a note of the current behavior, with
14 // the caveat that in the future, the rules may be loosened, at which
15 // point this test might be thrown out.
17 // The convention for the listed revisions: "lxl" means lexical
18 // lifetimes (which can be easier to reason about). "nll" means
19 // non-lexical lifetimes. "nll_target" means the initial conservative
20 // two-phase borrows that only applies to autoref-introduced borrows.
21 // "nll_beyond" means the generalization of two-phase borrows to all
22 // `&mut`-borrows (doing so makes it easier to write code for specific
26 let mut vec = vec![0, 1];
27 let delay: &mut Vec<_>;
31 // we reserve here, which could (on its own) be compatible
32 // with the shared borrow. But in the current implementation,
35 //[nll_beyond]~^ ERROR cannot borrow `vec` as mutable because it is also borrowed as immutable
36 //[nll_target]~^^ ERROR cannot borrow `vec` as mutable because it is also borrowed as immutable
41 // the &mut-borrow only becomes active way down here.
43 // (At least in theory; part of the reason this test fails is that
44 // the constructed MIR throws in extra &mut reborrows which
45 // flummoxes our attmpt to delay the activation point here.)