Skip to content

Commit 800be4c

Browse files
pnkfelixmatthewjasper
authored andcommitted
unit test for the lint itself, illustrating that it can be controlled by #[allow(..)] etc.
1 parent 9738d7a commit 800be4c

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Check that the future-compat-lint for the reservation conflict is
2+
// handled like any other lint.
3+
4+
// edition:2018
5+
6+
mod future_compat_allow {
7+
#![allow(mutable_borrow_reservation_conflict)]
8+
9+
fn reservation_conflict() {
10+
let mut v = vec![0, 1, 2];
11+
let shared = &v;
12+
13+
v.push(shared.len());
14+
}
15+
}
16+
17+
mod future_compat_warn {
18+
#![warn(mutable_borrow_reservation_conflict)]
19+
20+
fn reservation_conflict() {
21+
let mut v = vec![0, 1, 2];
22+
let shared = &v;
23+
24+
v.push(shared.len());
25+
//~^ WARNING cannot borrow `v` as mutable
26+
//~| WARNING will become a hard error in a future release
27+
}
28+
}
29+
30+
mod future_compat_deny {
31+
#![deny(mutable_borrow_reservation_conflict)]
32+
33+
fn reservation_conflict() {
34+
let mut v = vec![0, 1, 2];
35+
let shared = &v;
36+
37+
v.push(shared.len());
38+
//~^ ERROR cannot borrow `v` as mutable
39+
//~| WARNING will become a hard error in a future release
40+
}
41+
}
42+
43+
fn main() {}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
warning: cannot borrow `v` as mutable because it is also borrowed as immutable
2+
--> $DIR/two-phase-reservation-sharing-interference-future-compat-lint.rs:24:9
3+
|
4+
LL | let shared = &v;
5+
| -- immutable borrow occurs here
6+
LL |
7+
LL | v.push(shared.len());
8+
| ^ ------ immutable borrow later used here
9+
| |
10+
| mutable borrow occurs here
11+
|
12+
note: lint level defined here
13+
--> $DIR/two-phase-reservation-sharing-interference-future-compat-lint.rs:18:13
14+
|
15+
LL | #![warn(mutable_borrow_reservation_conflict)]
16+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
18+
= note: for more information, see issue #59159 <https://github.com/rust-lang/rust/issues/59159>
19+
20+
error: cannot borrow `v` as mutable because it is also borrowed as immutable
21+
--> $DIR/two-phase-reservation-sharing-interference-future-compat-lint.rs:37:9
22+
|
23+
LL | let shared = &v;
24+
| -- immutable borrow occurs here
25+
LL |
26+
LL | v.push(shared.len());
27+
| ^ ------ immutable borrow later used here
28+
| |
29+
| mutable borrow occurs here
30+
|
31+
note: lint level defined here
32+
--> $DIR/two-phase-reservation-sharing-interference-future-compat-lint.rs:31:13
33+
|
34+
LL | #![deny(mutable_borrow_reservation_conflict)]
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
37+
= note: for more information, see issue #59159 <https://github.com/rust-lang/rust/issues/59159>
38+
39+
error: aborting due to previous error
40+

0 commit comments

Comments
 (0)