about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2017-12-06 11:56:13 +0100
committerFelix S. Klock II <pnkfelix@pnkfx.org>2017-12-13 15:48:20 -0600
commitdb5420b6f244df4a18c45293de4648c1962b6bb6 (patch)
tree20de74db807db865f7fc5c787b21a7c1092d6008 /src
parentdbbec4d62d579ea786d53ca7eceeb4b243fb8bf1 (diff)
downloadrust-db5420b6f244df4a18c45293de4648c1962b6bb6.tar.gz
rust-db5420b6f244df4a18c45293de4648c1962b6bb6.zip
test describing a currently unsupported corner case.
Diffstat (limited to 'src')
-rw-r--r--src/test/compile-fail/borrowck/two-phase-reservation-sharing-interference.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/test/compile-fail/borrowck/two-phase-reservation-sharing-interference.rs b/src/test/compile-fail/borrowck/two-phase-reservation-sharing-interference.rs
new file mode 100644
index 00000000000..cc85315263a
--- /dev/null
+++ b/src/test/compile-fail/borrowck/two-phase-reservation-sharing-interference.rs
@@ -0,0 +1,46 @@
+// 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 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.
+
+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;
+        //[lxl]~^ ERROR cannot borrow `vec` as mutable because it is also borrowed as immutable
+        //[nll]~^^   ERROR cannot borrow `vec` as mutable because it is also borrowed as immutable
+
+        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
+    // flummoxes our attmpt to delay the activation point here.)
+    delay.push(2);
+}
+