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