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: lxl_beyond nll_beyond nll_target
15 //[lxl_beyond]compile-flags: -Z borrowck=mir -Z two-phase-borrows -Z two-phase-beyond-autoref
16 //[nll_beyond]compile-flags: -Z borrowck=mir -Z two-phase-borrows -Z two-phase-beyond-autoref -Z nll
17 //[nll_target]compile-flags: -Z borrowck=mir -Z two-phase-borrows -Z nll
19 // This is a corner case that the current implementation is (probably)
20 // treating more conservatively than is necessary. But it also does
21 // not seem like a terribly important use case to cover.
23 // So this test is just making a note of the current behavior, with
24 // the caveat that in the future, the rules may be loosened, at which
25 // point this test might be thrown out.
27 // The convention for the listed revisions: "lxl" means lexical
28 // lifetimes (which can be easier to reason about). "nll" means
29 // non-lexical lifetimes. "nll_target" means the initial conservative
30 // two-phase borrows that only applies to autoref-introduced borrows.
31 // "nll_beyond" means the generalization of two-phase borrows to all
32 // `&mut`-borrows (doing so makes it easier to write code for specific
35 // FIXME: in "nll_target", we currently see the same error reported
36 // twice. This is injected by `-Z two-phase-borrows`; not sure why as
40 let mut vec = vec![0, 1];
41 let delay: &mut Vec<_>;
45 // we reserve here, which could (on its own) be compatible
46 // with the shared borrow. But in the current implementation,
49 //[lxl_beyond]~^ ERROR cannot borrow `vec` as mutable because it is also borrowed as immutable
50 //[nll_beyond]~^^ ERROR cannot borrow `vec` as mutable because it is also borrowed as immutable
51 //[nll_target]~^^^ ERROR cannot borrow `vec` as mutable because it is also borrowed as immutable
52 //[nll_target]~| ERROR cannot borrow `vec` as mutable because it is also borrowed as immutable
57 // the &mut-borrow only becomes active way down here.
59 // (At least in theory; part of the reason this test fails is that
60 // the constructed MIR throws in extra &mut reborrows which
61 // flummoxes our attmpt to delay the activation point here.)