Skip to content

Commit 3b5fbb6

Browse files
authored
Rollup merge of #64221 - Centril:nll-no-migrate-2015, r=matthewjasper
Rust 2015: No longer downgrade NLL errors As per decision on a language team meeting as described in #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 #38899 Fixes #53432 Fixes #45157 Fixes #31567 Fixes #27868 Fixes #47366 r? @matthewjasper
2 parents 134004f + 5a0e461 commit 3b5fbb6

File tree

85 files changed

+176
-1849
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+176
-1849
lines changed

src/librustc_mir/borrow_check/conflict_errors.rs

-3
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
105105
format!("{} occurs due to use{}", desired_action.as_noun(), use_spans.describe()),
106106
);
107107

108-
// This error should not be downgraded to a warning,
109-
// even in migrate mode.
110-
self.disable_error_downgrading();
111108
err.buffer(&mut self.errors_buffer);
112109
} else {
113110
if let Some((reported_place, _)) = self.move_error_reported.get(&move_out_indices) {

src/librustc_mir/borrow_check/mod.rs

+1-57
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc::hir::def_id::DefId;
77
use rustc::infer::InferCtxt;
88
use rustc::lint::builtin::UNUSED_MUT;
99
use rustc::lint::builtin::{MUTABLE_BORROW_RESERVATION_CONFLICT};
10-
use rustc::middle::borrowck::SignalledError;
1110
use rustc::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind};
1211
use rustc::mir::{
1312
ClearCrossCrate, Local, Location, Body, Mutability, Operand, Place, PlaceBase, PlaceElem,
@@ -18,7 +17,7 @@ use rustc::mir::{Terminator, TerminatorKind};
1817
use rustc::ty::query::Providers;
1918
use rustc::ty::{self, TyCtxt};
2019

21-
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, Level};
20+
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder};
2221
use rustc_data_structures::bit_set::BitSet;
2322
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2423
use rustc_data_structures::graph::dominators::Dominators;
@@ -259,10 +258,6 @@ fn do_mir_borrowck<'a, 'tcx>(
259258
move_error_reported: BTreeMap::new(),
260259
uninitialized_error_reported: Default::default(),
261260
errors_buffer,
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(),
266261
nonlexical_regioncx: regioncx,
267262
used_mut: Default::default(),
268263
used_mut_upvars: SmallVec::new(),
@@ -374,33 +369,6 @@ fn do_mir_borrowck<'a, 'tcx>(
374369
if !mbcx.errors_buffer.is_empty() {
375370
mbcx.errors_buffer.sort_by_key(|diag| diag.span.primary_span());
376371

377-
if !mbcx.disable_error_downgrading && tcx.migrate_borrowck() {
378-
// When borrowck=migrate, check if AST-borrowck would
379-
// error on the given code.
380-
381-
// rust-lang/rust#55492, rust-lang/rust#58776 check the base def id
382-
// for errors. AST borrowck is responsible for aggregating
383-
// `signalled_any_error` from all of the nested closures here.
384-
let base_def_id = tcx.closure_base_def_id(def_id);
385-
386-
match tcx.borrowck(base_def_id).signalled_any_error {
387-
SignalledError::NoErrorsSeen => {
388-
// if AST-borrowck signalled no errors, then
389-
// downgrade all the buffered MIR-borrowck errors
390-
// to warnings.
391-
392-
for err in mbcx.errors_buffer.iter_mut() {
393-
downgrade_if_error(err);
394-
}
395-
}
396-
SignalledError::SawSomeError => {
397-
// if AST-borrowck signalled a (cancelled) error,
398-
// then we will just emit the buffered
399-
// MIR-borrowck errors as normal.
400-
}
401-
}
402-
}
403-
404372
for diag in mbcx.errors_buffer.drain(..) {
405373
mbcx.infcx.tcx.sess.diagnostic().emit_diagnostic(&diag);
406374
}
@@ -416,21 +384,6 @@ fn do_mir_borrowck<'a, 'tcx>(
416384
result
417385
}
418386

419-
fn downgrade_if_error(diag: &mut Diagnostic) {
420-
if diag.is_error() {
421-
diag.level = Level::Warning;
422-
diag.warn(
423-
"this error has been downgraded to a warning for backwards \
424-
compatibility with previous releases",
425-
).warn(
426-
"this represents potential undefined behavior in your code and \
427-
this warning will become a hard error in the future",
428-
).note(
429-
"for more information, try `rustc --explain E0729`"
430-
);
431-
}
432-
}
433-
434387
crate struct MirBorrowckCtxt<'cx, 'tcx> {
435388
crate infcx: &'cx InferCtxt<'cx, 'tcx>,
436389
body: &'cx Body<'tcx>,
@@ -491,9 +444,6 @@ crate struct MirBorrowckCtxt<'cx, 'tcx> {
491444
uninitialized_error_reported: FxHashSet<PlaceRef<'cx, 'tcx>>,
492445
/// Errors to be reported buffer
493446
errors_buffer: Vec<Diagnostic>,
494-
/// If there are no errors reported by the HIR borrow checker, we downgrade
495-
/// all NLL errors to warnings. Setting this flag disables downgrading.
496-
disable_error_downgrading: bool,
497447
/// This field keeps track of all the local variables that are declared mut and are mutated.
498448
/// Used for the warning issued by an unused mutable local variable.
499449
used_mut: FxHashSet<Local>,
@@ -934,12 +884,6 @@ impl InitializationRequiringAction {
934884
}
935885

936886
impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
937-
/// If there are no errors reported by the HIR borrow checker, we downgrade
938-
/// all NLL errors to warnings. Calling this disables downgrading.
939-
crate fn disable_error_downgrading(&mut self) {
940-
self.disable_error_downgrading = true;
941-
}
942-
943887
/// Checks an access to the given place to see if it is allowed. Examines the set of borrows
944888
/// that are in scope, as well as which paths have been initialized, to ensure that (a) the
945889
/// place is initialized and (b) it is not borrowed in some way that would prevent this

src/test/ui/borrowck/borrowck-anon-fields-variant.nll.stderr

-40
This file was deleted.

src/test/ui/borrowck/borrowck-anon-fields-variant.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ fn distinct_variant() {
1515
// reference.
1616
let b = match y {
1717
Foo::Y(_, ref mut b) => b,
18-
//~^ WARNING cannot use `y`
19-
//~| WARNING this error has been downgraded to a warning
20-
//~| WARNING this warning will become a hard error in the future
18+
//~^ ERROR cannot use `y`
2119
Foo::X => panic!()
2220
};
2321

src/test/ui/borrowck/borrowck-anon-fields-variant.stderr

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
warning[E0503]: cannot use `y` because it was mutably borrowed
1+
error[E0503]: cannot use `y` because it was mutably borrowed
22
--> $DIR/borrowck-anon-fields-variant.rs:17:7
33
|
44
LL | Foo::Y(ref mut a, _) => a,
@@ -9,13 +9,9 @@ LL | Foo::Y(_, ref mut b) => b,
99
...
1010
LL | *a += 1;
1111
| ------- borrow later used here
12-
|
13-
= warning: this error has been downgraded to a warning for backwards compatibility with previous releases
14-
= warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future
15-
= note: for more information, try `rustc --explain E0729`
1612

1713
error[E0503]: cannot use `y` because it was mutably borrowed
18-
--> $DIR/borrowck-anon-fields-variant.rs:37:7
14+
--> $DIR/borrowck-anon-fields-variant.rs:35:7
1915
|
2016
LL | Foo::Y(ref mut a, _) => a,
2117
| --------- borrow of `y.0` occurs here
@@ -27,7 +23,7 @@ LL | *a += 1;
2723
| ------- borrow later used here
2824

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

41-
error: aborting due to 2 previous errors
37+
error: aborting due to 3 previous errors
4238

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

0 commit comments

Comments
 (0)