2018-04-24 23:17:31 +00:00
|
|
|
//@ revisions: nll_target
|
2018-01-16 09:52:52 +00:00
|
|
|
|
2021-06-13 19:06:11 +00:00
|
|
|
// The nll_beyond revision is disabled due to missing support from two-phase beyond autorefs
|
2024-05-04 08:58:31 +00:00
|
|
|
//@ unused-revision-names: nll_beyond
|
2022-04-01 17:13:25 +00:00
|
|
|
//@[nll_beyond]compile-flags: -Z two-phase-beyond-autoref
|
2024-02-24 17:04:37 +00:00
|
|
|
//@[nll_beyond]should-fail
|
2018-03-05 07:44:10 +00:00
|
|
|
|
2017-12-06 10:56:13 +00:00
|
|
|
// This is a corner case that the current implementation is (probably)
|
|
|
|
// treating more conservatively than is necessary. But it also does
|
|
|
|
// not seem like a terribly important use case to cover.
|
|
|
|
//
|
|
|
|
// So this test is just making a note of the current behavior, with
|
|
|
|
// the caveat that in the future, the rules may be loosened, at which
|
|
|
|
// point this test might be thrown out.
|
2018-01-16 09:52:52 +00:00
|
|
|
//
|
|
|
|
// The convention for the listed revisions: "lxl" means lexical
|
|
|
|
// lifetimes (which can be easier to reason about). "nll" means
|
|
|
|
// non-lexical lifetimes. "nll_target" means the initial conservative
|
|
|
|
// two-phase borrows that only applies to autoref-introduced borrows.
|
|
|
|
// "nll_beyond" means the generalization of two-phase borrows to all
|
|
|
|
// `&mut`-borrows (doing so makes it easier to write code for specific
|
|
|
|
// corner cases).
|
2017-12-06 10:56:13 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut vec = vec![0, 1];
|
|
|
|
let delay: &mut Vec<_>;
|
|
|
|
{
|
|
|
|
let shared = &vec;
|
|
|
|
|
|
|
|
// we reserve here, which could (on its own) be compatible
|
|
|
|
// with the shared borrow. But in the current implementation,
|
|
|
|
// its an error.
|
|
|
|
delay = &mut vec;
|
2018-04-09 09:28:00 +00:00
|
|
|
//[nll_beyond]~^ ERROR cannot borrow `vec` as mutable because it is also borrowed as immutable
|
|
|
|
//[nll_target]~^^ ERROR cannot borrow `vec` as mutable because it is also borrowed as immutable
|
2017-12-06 10:56:13 +00:00
|
|
|
|
|
|
|
shared[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
// the &mut-borrow only becomes active way down here.
|
|
|
|
//
|
|
|
|
// (At least in theory; part of the reason this test fails is that
|
|
|
|
// the constructed MIR throws in extra &mut reborrows which
|
2022-08-18 02:13:37 +00:00
|
|
|
// flummoxes our attempt to delay the activation point here.)
|
2017-12-06 10:56:13 +00:00
|
|
|
delay.push(2);
|
|
|
|
}
|