Skip to content

Commit 0554095

Browse files
committed
Refuse to downgrade NLL errors on Rust >= 2018.
1 parent 2d168fa commit 0554095

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

src/librustc_mir/borrow_check/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,10 @@ fn do_mir_borrowck<'a, 'tcx>(
259259
move_error_reported: BTreeMap::new(),
260260
uninitialized_error_reported: Default::default(),
261261
errors_buffer,
262-
disable_error_downgrading: false,
262+
// Only downgrade errors on Rust 2015 and refuse to do so on Rust 2018.
263+
// FIXME(Centril): In Rust 1.40.0, refuse doing so on 2015 as well and
264+
// proceed to throwing out the migration infrastructure.
265+
disable_error_downgrading: body.span.rust_2018(),
263266
nonlexical_regioncx: regioncx,
264267
used_mut: Default::default(),
265268
used_mut_upvars: SmallVec::new(),
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
warning[E0502]: cannot borrow `*block.current` as immutable because it is also borrowed as mutable
2-
--> $DIR/borrowck-migrate-to-nll.rs:28:21
1+
error[E0502]: cannot borrow `*block.current` as immutable because it is also borrowed as mutable
2+
--> $DIR/borrowck-migrate-to-nll.rs:29:21
33
|
44
LL | let x = &mut block;
55
| ---------- mutable borrow occurs here
66
LL | let p: &'a u8 = &*block.current;
77
| ^^^^^^^^^^^^^^^ immutable borrow occurs here
8-
LL | // (use `x` and `p` so enabling NLL doesn't assign overly short lifetimes)
8+
...
99
LL | drop(x);
1010
| - mutable borrow later used here
11-
|
12-
= warning: this error has been downgraded to a warning for backwards compatibility with previous releases
13-
= warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future
14-
= note: for more information, try `rustc --explain E0729`
1511

12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0502`.

src/test/ui/borrowck/borrowck-migrate-to-nll.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//
55
// Therefore, for backwards-compatiblity, under borrowck=migrate the
66
// NLL checks will be emitted as *warnings*.
7+
//
8+
// In Rust 2018, no errors will be downgraded to warnings.
79

810
// NLL mode makes this compile-fail; we cannot currently encode a
911
// test that is run-pass or compile-fail based on compare-mode. So
@@ -16,7 +18,6 @@
1618
//[zflag]compile-flags: -Z borrowck=migrate
1719
//[edition]edition:2018
1820
//[zflag] run-pass
19-
//[edition] run-pass
2021

2122
pub struct Block<'a> {
2223
current: &'a u8,
@@ -26,6 +27,7 @@ pub struct Block<'a> {
2627
fn bump<'a>(mut block: &mut Block<'a>) {
2728
let x = &mut block;
2829
let p: &'a u8 = &*block.current;
30+
//[edition]~^ ERROR cannot borrow `*block.current` as immutable
2931
// (use `x` and `p` so enabling NLL doesn't assign overly short lifetimes)
3032
drop(x);
3133
drop(p);

src/test/ui/borrowck/borrowck-migrate-to-nll.zflag.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
warning[E0502]: cannot borrow `*block.current` as immutable because it is also borrowed as mutable
2-
--> $DIR/borrowck-migrate-to-nll.rs:28:21
2+
--> $DIR/borrowck-migrate-to-nll.rs:29:21
33
|
44
LL | let x = &mut block;
55
| ---------- mutable borrow occurs here
66
LL | let p: &'a u8 = &*block.current;
77
| ^^^^^^^^^^^^^^^ immutable borrow occurs here
8-
LL | // (use `x` and `p` so enabling NLL doesn't assign overly short lifetimes)
8+
...
99
LL | drop(x);
1010
| - mutable borrow later used here
1111
|

0 commit comments

Comments
 (0)