From 800be4c07c90856cca8a74efc7075ddff788d66d Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 13 Mar 2019 22:16:56 +0100 Subject: [PATCH] unit test for the lint itself, illustrating that it can be controlled by `#[allow(..)]` etc. --- ...sharing-interference-future-compat-lint.rs | 43 +++++++++++++++++++ ...ing-interference-future-compat-lint.stderr | 40 +++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.rs create mode 100644 src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.stderr 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 000000000000..d3d28b11c51c --- /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 000000000000..a1a0de48ff13 --- /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 + +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 + +error: aborting due to previous error +