From 9cb92ac27d12c7ded8a1ad736b23e2fe1c99577e Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 6 Dec 2017 12:25:36 +0100 Subject: [PATCH] two-phase-reservation-sharing-interference.rs variant that is perhaps more surprising. --- ...hase-reservation-sharing-interference-2.rs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/test/compile-fail/borrowck/two-phase-reservation-sharing-interference-2.rs diff --git a/src/test/compile-fail/borrowck/two-phase-reservation-sharing-interference-2.rs b/src/test/compile-fail/borrowck/two-phase-reservation-sharing-interference-2.rs new file mode 100644 index 000000000000..397b3dafa7d4 --- /dev/null +++ b/src/test/compile-fail/borrowck/two-phase-reservation-sharing-interference-2.rs @@ -0,0 +1,38 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// revisions: lxl nll +//[lxl]compile-flags: -Z borrowck=mir -Z two-phase-borrows +//[nll]compile-flags: -Z borrowck=mir -Z two-phase-borrows -Z nll + +// This is similar to two-phase-reservation-sharing-interference.rs +// in that it shows a reservation that overlaps with a shared borrow. +// +// However, it is also more immediately concerning because one would +// intutively think that if run-pass/borrowck/two-phase-baseline.rs +// works, then this *should* work too. +// +// As before, the current implementation is (probably) more +// conservative than is necessary. +// +// 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. + +fn main() { + let mut v = vec![0, 1, 2]; + let shared = &v; + + v.push(shared.len()); + //[lxl]~^ ERROR cannot borrow `v` as mutable because it is also borrowed as immutable [E0502] + //[nll]~^^ ERROR cannot borrow `v` as mutable because it is also borrowed as immutable [E0502] + + assert_eq!(v, [0, 1, 2, 3]); +}