Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unit test for the lint itself, illustrating that it can be controlled…
… by `#[allow(..)]` etc.
- Loading branch information
1 parent
9738d7a
commit 800be4c
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
40 changes: 40 additions & 0 deletions
40
src/test/ui/borrowck/two-phase-reservation-sharing-interference-future-compat-lint.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|