unit test for the lint itself, illustrating that it can be controlled by #[allow(..)] etc.
This commit is contained in:
parent
9738d7acd8
commit
800be4c07c
2 changed files with 83 additions and 0 deletions
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue