about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2017-12-06 12:25:36 +0100
committerFelix S. Klock II <pnkfelix@pnkfx.org>2017-12-13 15:48:21 -0600
commit9cb92ac27d12c7ded8a1ad736b23e2fe1c99577e (patch)
treee111c32bf786b4c1cbe6c440985ce5d3d98d78af
parentdb5420b6f244df4a18c45293de4648c1962b6bb6 (diff)
downloadrust-9cb92ac27d12c7ded8a1ad736b23e2fe1c99577e.tar.gz
rust-9cb92ac27d12c7ded8a1ad736b23e2fe1c99577e.zip
two-phase-reservation-sharing-interference.rs variant that is perhaps more surprising.
-rw-r--r--src/test/compile-fail/borrowck/two-phase-reservation-sharing-interference-2.rs38
1 files changed, 38 insertions, 0 deletions
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 00000000000..397b3dafa7d
--- /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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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]);
+}