about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.rs43
-rw-r--r--src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.stderr40
2 files changed, 83 insertions, 0 deletions
diff --git a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.rs b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.rs
new file mode 100644
index 00000000000..d3d28b11c51
--- /dev/null
+++ b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.rs
@@ -0,0 +1,43 @@
+// Check that the future-compat-lint for the reservation conflict is
+// handled like any other lint.
+
+// edition:2018
+
+mod future_compat_allow {
+    #![allow(mutable_borrow_reservation_conflict)]
+
+    fn reservation_conflict() {
+        let mut v = vec![0, 1, 2];
+        let shared = &v;
+
+        v.push(shared.len());
+    }
+}
+
+mod future_compat_warn {
+    #![warn(mutable_borrow_reservation_conflict)]
+
+    fn reservation_conflict() {
+        let mut v = vec![0, 1, 2];
+        let shared = &v;
+
+        v.push(shared.len());
+        //~^ WARNING cannot borrow `v` as mutable
+        //~| WARNING will become a hard error in a future release
+    }
+}
+
+mod future_compat_deny {
+    #![deny(mutable_borrow_reservation_conflict)]
+
+    fn reservation_conflict() {
+        let mut v = vec![0, 1, 2];
+        let shared = &v;
+
+        v.push(shared.len());
+        //~^ ERROR cannot borrow `v` as mutable
+        //~| WARNING will become a hard error in a future release
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.stderr b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.stderr
new file mode 100644
index 00000000000..a1a0de48ff1
--- /dev/null
+++ b/src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.stderr
@@ -0,0 +1,40 @@
+warning: cannot borrow `v` as mutable because it is also borrowed as immutable
+  --> $DIR/two-phase-reservation-sharing-interference-future-compat-lint.rs:24:9
+   |
+LL |         let shared = &v;
+   |                      -- immutable borrow occurs here
+LL | 
+LL |         v.push(shared.len());
+   |         ^      ------ immutable borrow later used here
+   |         |
+   |         mutable borrow occurs here
+   |
+note: lint level defined here
+  --> $DIR/two-phase-reservation-sharing-interference-future-compat-lint.rs:18:13
+   |
+LL |     #![warn(mutable_borrow_reservation_conflict)]
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #59159 <https://github.com/rust-lang/rust/issues/59159>
+
+error: cannot borrow `v` as mutable because it is also borrowed as immutable
+  --> $DIR/two-phase-reservation-sharing-interference-future-compat-lint.rs:37:9
+   |
+LL |         let shared = &v;
+   |                      -- immutable borrow occurs here
+LL | 
+LL |         v.push(shared.len());
+   |         ^      ------ immutable borrow later used here
+   |         |
+   |         mutable borrow occurs here
+   |
+note: lint level defined here
+  --> $DIR/two-phase-reservation-sharing-interference-future-compat-lint.rs:31:13
+   |
+LL |     #![deny(mutable_borrow_reservation_conflict)]
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #59159 <https://github.com/rust-lang/rust/issues/59159>
+
+error: aborting due to previous error
+