Skip to content
Permalink
Browse files

unit test for the lint itself, illustrating that it can be controlled…

… by `#[allow(..)]` etc.
  • Loading branch information...
pnkfelix authored and matthewjasper committed Mar 13, 2019
1 parent 9738d7a commit 800be4c07c90856cca8a74efc7075ddff788d66d
@@ -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() {}
@@ -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

0 comments on commit 800be4c

Please sign in to comment.
You can’t perform that action at this time.