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