Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust 2018: NLL migrate mode => hard error #63565

Merged
merged 2 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ fn do_mir_borrowck<'a, 'tcx>(
};

let mdpe = MoveDataParamEnv {
move_data: move_data,
param_env: param_env,
move_data,
param_env,
};

let dead_unwinds = BitSet::new_empty(body.basic_blocks().len());
Expand Down Expand Up @@ -259,7 +259,10 @@ fn do_mir_borrowck<'a, 'tcx>(
move_error_reported: BTreeMap::new(),
uninitialized_error_reported: Default::default(),
errors_buffer,
disable_error_downgrading: false,
// Only downgrade errors on Rust 2015 and refuse to do so on Rust 2018.
// FIXME(Centril): In Rust 1.40.0, refuse doing so on 2015 as well and
// proceed to throwing out the migration infrastructure.
disable_error_downgrading: body.span.rust_2018(),
nonlexical_regioncx: regioncx,
used_mut: Default::default(),
used_mut_upvars: SmallVec::new(),
Expand Down
13 changes: 6 additions & 7 deletions src/test/ui/borrowck/borrowck-migrate-to-nll.edition.stderr
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
warning[E0502]: cannot borrow `*block.current` as immutable because it is also borrowed as mutable
--> $DIR/borrowck-migrate-to-nll.rs:28:21
error[E0502]: cannot borrow `*block.current` as immutable because it is also borrowed as mutable
--> $DIR/borrowck-migrate-to-nll.rs:29:21
|
LL | let x = &mut block;
| ---------- mutable borrow occurs here
LL | let p: &'a u8 = &*block.current;
| ^^^^^^^^^^^^^^^ immutable borrow occurs here
LL | // (use `x` and `p` so enabling NLL doesn't assign overly short lifetimes)
...
LL | drop(x);
| - mutable borrow later used here
|
= warning: this error has been downgraded to a warning for backwards compatibility with previous releases
= warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future
= note: for more information, try `rustc --explain E0729`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0502`.
4 changes: 3 additions & 1 deletion src/test/ui/borrowck/borrowck-migrate-to-nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//
// Therefore, for backwards-compatiblity, under borrowck=migrate the
// NLL checks will be emitted as *warnings*.
//
// In Rust 2018, no errors will be downgraded to warnings.

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

pub struct Block<'a> {
current: &'a u8,
Expand All @@ -26,6 +27,7 @@ pub struct Block<'a> {
fn bump<'a>(mut block: &mut Block<'a>) {
let x = &mut block;
let p: &'a u8 = &*block.current;
//[edition]~^ ERROR cannot borrow `*block.current` as immutable
// (use `x` and `p` so enabling NLL doesn't assign overly short lifetimes)
drop(x);
drop(p);
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/borrowck/borrowck-migrate-to-nll.zflag.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
warning[E0502]: cannot borrow `*block.current` as immutable because it is also borrowed as mutable
--> $DIR/borrowck-migrate-to-nll.rs:28:21
--> $DIR/borrowck-migrate-to-nll.rs:29:21
|
LL | let x = &mut block;
| ---------- mutable borrow occurs here
LL | let p: &'a u8 = &*block.current;
| ^^^^^^^^^^^^^^^ immutable borrow occurs here
LL | // (use `x` and `p` so enabling NLL doesn't assign overly short lifetimes)
...
LL | drop(x);
| - mutable borrow later used here
|
Expand Down