Skip to content

Commit

Permalink
Rollup merge of rust-lang#64221 - Centril:nll-no-migrate-2015, r=matt…
Browse files Browse the repository at this point in the history
…hewjasper

 Rust 2015: No longer downgrade NLL errors

As per decision on a language team meeting as described in rust-lang#63565 (comment), in Rust 2015, we refuse to downgrade NLL errors, that AST borrowck accepts, into warnings and keep them as hard errors.

The remaining work to throw out AST borrowck and adjust some tests still remains after this PR.

Fixes rust-lang#38899
Fixes rust-lang#53432
Fixes rust-lang#45157
Fixes rust-lang#31567
Fixes rust-lang#27868
Fixes rust-lang#47366

r? @matthewjasper
  • Loading branch information
Centril committed Sep 26, 2019
2 parents 7b0167a + 4503ad4 commit 6f0448c
Show file tree
Hide file tree
Showing 82 changed files with 170 additions and 1,382 deletions.
3 changes: 0 additions & 3 deletions src/librustc_mir/borrow_check/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
format!("{} occurs due to use{}", desired_action.as_noun(), use_spans.describe()),
);

// This error should not be downgraded to a warning,
// even in migrate mode.
self.disable_error_downgrading();
err.buffer(&mut self.errors_buffer);
} else {
if let Some((reported_place, _)) = self.move_error_reported.get(&move_out_indices) {
Expand Down
58 changes: 1 addition & 57 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use rustc::hir::def_id::DefId;
use rustc::infer::InferCtxt;
use rustc::lint::builtin::UNUSED_MUT;
use rustc::lint::builtin::{MUTABLE_BORROW_RESERVATION_CONFLICT};
use rustc::middle::borrowck::SignalledError;
use rustc::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind};
use rustc::mir::{
ClearCrossCrate, Local, Location, Body, Mutability, Operand, Place, PlaceBase, PlaceElem,
Expand All @@ -18,7 +17,7 @@ use rustc::mir::{Terminator, TerminatorKind};
use rustc::ty::query::Providers;
use rustc::ty::{self, TyCtxt};

use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, Level};
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder};
use rustc_data_structures::bit_set::BitSet;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::graph::dominators::Dominators;
Expand Down Expand Up @@ -259,10 +258,6 @@ fn do_mir_borrowck<'a, 'tcx>(
move_error_reported: BTreeMap::new(),
uninitialized_error_reported: Default::default(),
errors_buffer,
// 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 Expand Up @@ -374,33 +369,6 @@ fn do_mir_borrowck<'a, 'tcx>(
if !mbcx.errors_buffer.is_empty() {
mbcx.errors_buffer.sort_by_key(|diag| diag.span.primary_span());

if !mbcx.disable_error_downgrading && tcx.migrate_borrowck() {
// When borrowck=migrate, check if AST-borrowck would
// error on the given code.

// rust-lang/rust#55492, rust-lang/rust#58776 check the base def id
// for errors. AST borrowck is responsible for aggregating
// `signalled_any_error` from all of the nested closures here.
let base_def_id = tcx.closure_base_def_id(def_id);

match tcx.borrowck(base_def_id).signalled_any_error {
SignalledError::NoErrorsSeen => {
// if AST-borrowck signalled no errors, then
// downgrade all the buffered MIR-borrowck errors
// to warnings.

for err in mbcx.errors_buffer.iter_mut() {
downgrade_if_error(err);
}
}
SignalledError::SawSomeError => {
// if AST-borrowck signalled a (cancelled) error,
// then we will just emit the buffered
// MIR-borrowck errors as normal.
}
}
}

for diag in mbcx.errors_buffer.drain(..) {
mbcx.infcx.tcx.sess.diagnostic().emit_diagnostic(&diag);
}
Expand All @@ -416,21 +384,6 @@ fn do_mir_borrowck<'a, 'tcx>(
result
}

fn downgrade_if_error(diag: &mut Diagnostic) {
if diag.is_error() {
diag.level = Level::Warning;
diag.warn(
"this error has been downgraded to a warning for backwards \
compatibility with previous releases",
).warn(
"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`"
);
}
}

crate struct MirBorrowckCtxt<'cx, 'tcx> {
crate infcx: &'cx InferCtxt<'cx, 'tcx>,
body: &'cx Body<'tcx>,
Expand Down Expand Up @@ -491,9 +444,6 @@ crate struct MirBorrowckCtxt<'cx, 'tcx> {
uninitialized_error_reported: FxHashSet<PlaceRef<'cx, 'tcx>>,
/// Errors to be reported buffer
errors_buffer: Vec<Diagnostic>,
/// If there are no errors reported by the HIR borrow checker, we downgrade
/// all NLL errors to warnings. Setting this flag disables downgrading.
disable_error_downgrading: bool,
/// This field keeps track of all the local variables that are declared mut and are mutated.
/// Used for the warning issued by an unused mutable local variable.
used_mut: FxHashSet<Local>,
Expand Down Expand Up @@ -934,12 +884,6 @@ impl InitializationRequiringAction {
}

impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
/// If there are no errors reported by the HIR borrow checker, we downgrade
/// all NLL errors to warnings. Calling this disables downgrading.
crate fn disable_error_downgrading(&mut self) {
self.disable_error_downgrading = true;
}

/// Checks an access to the given place to see if it is allowed. Examines the set of borrows
/// that are in scope, as well as which paths have been initialized, to ensure that (a) the
/// place is initialized and (b) it is not borrowed in some way that would prevent this
Expand Down
40 changes: 0 additions & 40 deletions src/test/ui/borrowck/borrowck-anon-fields-variant.nll.stderr

This file was deleted.

4 changes: 1 addition & 3 deletions src/test/ui/borrowck/borrowck-anon-fields-variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ fn distinct_variant() {
// reference.
let b = match y {
Foo::Y(_, ref mut b) => b,
//~^ WARNING cannot use `y`
//~| WARNING this error has been downgraded to a warning
//~| WARNING this warning will become a hard error in the future
//~^ ERROR cannot use `y`
Foo::X => panic!()
};

Expand Down
12 changes: 4 additions & 8 deletions src/test/ui/borrowck/borrowck-anon-fields-variant.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
warning[E0503]: cannot use `y` because it was mutably borrowed
error[E0503]: cannot use `y` because it was mutably borrowed
--> $DIR/borrowck-anon-fields-variant.rs:17:7
|
LL | Foo::Y(ref mut a, _) => a,
Expand All @@ -9,13 +9,9 @@ LL | Foo::Y(_, ref mut b) => b,
...
LL | *a += 1;
| ------- 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[E0503]: cannot use `y` because it was mutably borrowed
--> $DIR/borrowck-anon-fields-variant.rs:37:7
--> $DIR/borrowck-anon-fields-variant.rs:35:7
|
LL | Foo::Y(ref mut a, _) => a,
| --------- borrow of `y.0` occurs here
Expand All @@ -27,7 +23,7 @@ LL | *a += 1;
| ------- borrow later used here

error[E0499]: cannot borrow `y.0` as mutable more than once at a time
--> $DIR/borrowck-anon-fields-variant.rs:37:14
--> $DIR/borrowck-anon-fields-variant.rs:35:14
|
LL | Foo::Y(ref mut a, _) => a,
| --------- first mutable borrow occurs here
Expand All @@ -38,7 +34,7 @@ LL | Foo::Y(ref mut b, _) => b,
LL | *a += 1;
| ------- first borrow later used here

error: aborting due to 2 previous errors
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0499, E0503.
For more information about an error, try `rustc --explain E0499`.
Loading

0 comments on commit 6f0448c

Please sign in to comment.