Skip to content

Commit 4f61eac

Browse files
authoredSep 6, 2019
Rollup merge of rust-lang#63565 - Centril:deny-nll-migrate-mode, r=matthewjasper
Rust 2018: NLL migrate mode => hard error As per decision on a language team meeting as described in rust-lang#63565 (comment), we refuse to downgrade NLL errors, that AST borrowck accepts, into warnings and keep them as hard errors. cc @rust-lang/lang cc @rust-lang/wg-compiler-nll
2 parents 4894123 + 0554095 commit 4f61eac

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed
 

‎src/librustc_mir/borrow_check/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ fn do_mir_borrowck<'a, 'tcx>(
164164
};
165165

166166
let mdpe = MoveDataParamEnv {
167-
move_data: move_data,
168-
param_env: param_env,
167+
move_data,
168+
param_env,
169169
};
170170

171171
let dead_unwinds = BitSet::new_empty(body.basic_blocks().len());
@@ -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)
Please sign in to comment.