From 055409538d601e905d72a08dd6c28256587fba3d Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Fri, 6 Sep 2019 10:39:38 +0200 Subject: [PATCH] Refuse to downgrade NLL errors on Rust >= 2018. --- src/librustc_mir/borrow_check/mod.rs | 5 ++++- .../borrowck/borrowck-migrate-to-nll.edition.stderr | 13 ++++++------- src/test/ui/borrowck/borrowck-migrate-to-nll.rs | 4 +++- .../borrowck/borrowck-migrate-to-nll.zflag.stderr | 4 ++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 5c397ff3019db..9ad7cbc478bb0 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -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(), diff --git a/src/test/ui/borrowck/borrowck-migrate-to-nll.edition.stderr b/src/test/ui/borrowck/borrowck-migrate-to-nll.edition.stderr index a33a1d00a5786..58f2cadcc6573 100644 --- a/src/test/ui/borrowck/borrowck-migrate-to-nll.edition.stderr +++ b/src/test/ui/borrowck/borrowck-migrate-to-nll.edition.stderr @@ -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`. diff --git a/src/test/ui/borrowck/borrowck-migrate-to-nll.rs b/src/test/ui/borrowck/borrowck-migrate-to-nll.rs index 6dda317e57efe..98fd5682277b3 100644 --- a/src/test/ui/borrowck/borrowck-migrate-to-nll.rs +++ b/src/test/ui/borrowck/borrowck-migrate-to-nll.rs @@ -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 @@ -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, @@ -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); diff --git a/src/test/ui/borrowck/borrowck-migrate-to-nll.zflag.stderr b/src/test/ui/borrowck/borrowck-migrate-to-nll.zflag.stderr index a33a1d00a5786..ace336a3bf32a 100644 --- a/src/test/ui/borrowck/borrowck-migrate-to-nll.zflag.stderr +++ b/src/test/ui/borrowck/borrowck-migrate-to-nll.zflag.stderr @@ -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 |