Skip to content

Commit bf0ea60

Browse files
committed
Auto merge of #59114 - matthewjasper:enable-migate-2015, r=pnkfelix
Enable NLL migrate mode on the 2015 edition ## What is in this PR? * Remove the `-Zborrowck=ast` flag option from rustc. * The default in the 2015 edition is now `-Zborrowck=migrate`. * The 2018 edition default is unchanged: it's still `-Zborrowck=migrate`. * Enable two-phase borrows (currently toggled via the `-Ztwo-phase-borrows` flag) on all editions. * Remove most dead code that handled these options. * Update tests for the above changes. ## What is *not* in this PR? These are left for future PRs * Use `-Zborrowck=mir` in NLL compare mode tests (#56993) * Remove the `-Zborrowck=compare` option (#59193) * Remove the `-Ztwo-phase-borrows` flag. It's kept, as a flag that does nothing so that perf.rlo has time to stop using it (cc @Mark-Simulacrum) * Remove MIR typeck as its own MIR pass - it's now run by NLL. * Enabling `-Zborrowck=mir` by default (#58781) * Replace `allow_bind_by_move_patterns_with_guards` and `check_for_mutation_in_guard_via_ast_walk` with just using the feature gate. (#59192) Soundness issues that are fixed by NLL will stay open until full NLL is emitting hard errors. However, these diagnostics and completeness issues can now be closed: Closes #18330 Closes #22323 Closes #23591 Closes #26736 Closes #27487 Closes #28092 Closes #28970 Closes #29733 Closes #30104 Closes #38915 Closes #39908 Closes #43407 Closes #47524 Closes #48540 Closes #49073 Closes #52614 Closes #55085 Closes #56093 Closes #56496 Closes #57804 cc #43234 r? @pnkfelix cc @rust-lang/lang cc @rust-lang/wg-compiler-nll
2 parents 247b505 + 18c0632 commit bf0ea60

File tree

1,373 files changed

+6035
-22258
lines changed

Some content is hidden

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

1,373 files changed

+6035
-22258
lines changed

src/librustc/infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ impl SuppressRegionErrors {
9292
/// enabled.
9393
pub fn when_nll_is_enabled(tcx: TyCtxt<'_, '_, '_>) -> Self {
9494
match tcx.borrowck_mode() {
95-
// If we're on AST or Migrate mode, report AST region errors
96-
BorrowckMode::Ast | BorrowckMode::Migrate => SuppressRegionErrors { suppressed: false },
95+
// If we're on Migrate mode, report AST region errors
96+
BorrowckMode::Migrate => SuppressRegionErrors { suppressed: false },
9797

9898
// If we're on MIR or Compare mode, don't report AST region errors as they should
9999
// be reported by NLL

src/librustc/session/config.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ pub enum PrintRequest {
460460

461461
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
462462
pub enum BorrowckMode {
463-
Ast,
464463
Mir,
465464
Compare,
466465
Migrate,
@@ -471,7 +470,6 @@ impl BorrowckMode {
471470
/// on the AST borrow check if the MIR-based one errors.
472471
pub fn migrate(self) -> bool {
473472
match self {
474-
BorrowckMode::Ast => false,
475473
BorrowckMode::Compare => false,
476474
BorrowckMode::Mir => false,
477475
BorrowckMode::Migrate => true,
@@ -481,21 +479,11 @@ impl BorrowckMode {
481479
/// Should we emit the AST-based borrow checker errors?
482480
pub fn use_ast(self) -> bool {
483481
match self {
484-
BorrowckMode::Ast => true,
485482
BorrowckMode::Compare => true,
486483
BorrowckMode::Mir => false,
487484
BorrowckMode::Migrate => false,
488485
}
489486
}
490-
/// Should we emit the MIR-based borrow checker errors?
491-
pub fn use_mir(self) -> bool {
492-
match self {
493-
BorrowckMode::Ast => false,
494-
BorrowckMode::Compare => true,
495-
BorrowckMode::Mir => true,
496-
BorrowckMode::Migrate => true,
497-
}
498-
}
499487
}
500488

501489
pub enum Input {
@@ -627,7 +615,7 @@ impl Default for Options {
627615
incremental: None,
628616
debugging_opts: basic_debugging_options(),
629617
prints: Vec::new(),
630-
borrowck_mode: BorrowckMode::Ast,
618+
borrowck_mode: BorrowckMode::Migrate,
631619
cg: basic_codegen_options(),
632620
error_format: ErrorOutputType::default(),
633621
externs: Externs(BTreeMap::new()),
@@ -2326,10 +2314,9 @@ pub fn build_session_options_and_crate_config(
23262314
}));
23272315

23282316
let borrowck_mode = match debugging_opts.borrowck.as_ref().map(|s| &s[..]) {
2329-
None | Some("ast") => BorrowckMode::Ast,
2317+
None | Some("migrate") => BorrowckMode::Migrate,
23302318
Some("mir") => BorrowckMode::Mir,
23312319
Some("compare") => BorrowckMode::Compare,
2332-
Some("migrate") => BorrowckMode::Migrate,
23332320
Some(m) => early_error(error_format, &format!("unknown borrowck mode `{}`", m)),
23342321
};
23352322

src/librustc/ty/context.rs

+7-53
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ use rustc_macros::HashStable;
7070
use syntax::ast;
7171
use syntax::attr;
7272
use syntax::source_map::MultiSpan;
73-
use syntax::edition::Edition;
7473
use syntax::feature_gate;
7574
use syntax::symbol::{Symbol, keywords, InternedString};
7675
use syntax_pos::Span;
@@ -1496,21 +1495,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
14961495
/// because that method has a narrower effect that can be toggled
14971496
/// off via a separate `-Z` flag, at least for the short term.
14981497
pub fn allow_bind_by_move_patterns_with_guards(self) -> bool {
1499-
self.features().bind_by_move_pattern_guards && self.use_mir_borrowck()
1498+
self.features().bind_by_move_pattern_guards
15001499
}
15011500

15021501
/// If true, we should use a naive AST walk to determine if match
15031502
/// guard could perform bad mutations (or mutable-borrows).
15041503
pub fn check_for_mutation_in_guard_via_ast_walk(self) -> bool {
1505-
// If someone requests the feature, then be a little more
1506-
// careful and ensure that MIR-borrowck is enabled (which can
1507-
// happen via edition selection, via `feature(nll)`, or via an
1508-
// appropriate `-Z` flag) before disabling the mutation check.
1509-
if self.allow_bind_by_move_patterns_with_guards() {
1510-
return false;
1511-
}
1512-
1513-
return true;
1504+
!self.allow_bind_by_move_patterns_with_guards()
15141505
}
15151506

15161507
/// If true, we should use the AST-based borrowck (we may *also* use
@@ -1519,12 +1510,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
15191510
self.borrowck_mode().use_ast()
15201511
}
15211512

1522-
/// If true, we should use the MIR-based borrowck (we may *also* use
1523-
/// the AST-based borrowck).
1524-
pub fn use_mir_borrowck(self) -> bool {
1525-
self.borrowck_mode().use_mir()
1526-
}
1527-
15281513
/// If true, we should use the MIR-based borrow check, but also
15291514
/// fall back on the AST borrow check if the MIR-based one errors.
15301515
pub fn migrate_borrowck(self) -> bool {
@@ -1541,38 +1526,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
15411526
/// statements (which simulate the maximal effect of executing the
15421527
/// patterns in a match arm).
15431528
pub fn emit_read_for_match(&self) -> bool {
1544-
self.use_mir_borrowck() && !self.sess.opts.debugging_opts.nll_dont_emit_read_for_match
1545-
}
1546-
1547-
/// If true, pattern variables for use in guards on match arms
1548-
/// will be bound as references to the data, and occurrences of
1549-
/// those variables in the guard expression will implicitly
1550-
/// dereference those bindings. (See rust-lang/rust#27282.)
1551-
pub fn all_pat_vars_are_implicit_refs_within_guards(self) -> bool {
1552-
self.borrowck_mode().use_mir()
1553-
}
1554-
1555-
/// If true, we should enable two-phase borrows checks. This is
1556-
/// done with either: `-Ztwo-phase-borrows`, `#![feature(nll)]`,
1557-
/// or by opting into an edition after 2015.
1558-
pub fn two_phase_borrows(self) -> bool {
1559-
self.sess.rust_2018() || self.features().nll ||
1560-
self.sess.opts.debugging_opts.two_phase_borrows
1529+
!self.sess.opts.debugging_opts.nll_dont_emit_read_for_match
15611530
}
15621531

15631532
/// What mode(s) of borrowck should we run? AST? MIR? both?
15641533
/// (Also considers the `#![feature(nll)]` setting.)
15651534
pub fn borrowck_mode(&self) -> BorrowckMode {
15661535
// Here are the main constraints we need to deal with:
15671536
//
1568-
// 1. An opts.borrowck_mode of `BorrowckMode::Ast` is
1537+
// 1. An opts.borrowck_mode of `BorrowckMode::Migrate` is
15691538
// synonymous with no `-Z borrowck=...` flag at all.
1570-
// (This is arguably a historical accident.)
1571-
//
1572-
// 2. `BorrowckMode::Migrate` is the limited migration to
1573-
// NLL that we are deploying with the 2018 edition.
15741539
//
1575-
// 3. We want to allow developers on the Nightly channel
1540+
// 2. We want to allow developers on the Nightly channel
15761541
// to opt back into the "hard error" mode for NLL,
15771542
// (which they can do via specifying `#![feature(nll)]`
15781543
// explicitly in their crate).
@@ -1585,24 +1550,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
15851550
// a user's attempt to specify `-Z borrowck=compare`, which
15861551
// we arguably do not need anymore and should remove.)
15871552
//
1588-
// * Otherwise, if no `-Z borrowck=...` flag was given (or
1589-
// if `borrowck=ast` was specified), then use the default
1590-
// as required by the edition.
1553+
// * Otherwise, if no `-Z borrowck=...` then use migrate mode
15911554
//
15921555
// * Otherwise, use the behavior requested via `-Z borrowck=...`
15931556

15941557
if self.features().nll { return BorrowckMode::Mir; }
15951558

1596-
match self.sess.opts.borrowck_mode {
1597-
mode @ BorrowckMode::Mir |
1598-
mode @ BorrowckMode::Compare |
1599-
mode @ BorrowckMode::Migrate => mode,
1600-
1601-
BorrowckMode::Ast => match self.sess.edition() {
1602-
Edition::Edition2015 => BorrowckMode::Ast,
1603-
Edition::Edition2018 => BorrowckMode::Migrate,
1604-
},
1605-
}
1559+
self.sess.opts.borrowck_mode
16061560
}
16071561

16081562
#[inline]

src/librustc_borrowck/borrowck/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ pub mod gather_loans;
4949

5050
pub mod move_data;
5151

52-
mod unused;
53-
5452
#[derive(Clone, Copy)]
5553
pub struct LoanDataFlowOperator;
5654

@@ -138,10 +136,6 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId)
138136
check_loans::check_loans(&mut bccx, &loan_dfcx, &flowed_moves, &all_loans, body);
139137
}
140138

141-
if !tcx.use_mir_borrowck() {
142-
unused::check(&mut bccx, body);
143-
}
144-
145139
Lrc::new(BorrowCheckResult {
146140
used_mut_nodes: bccx.used_mut_nodes.into_inner(),
147141
signalled_any_error: bccx.signalled_any_error.into_inner(),

src/librustc_borrowck/borrowck/unused.rs

-116
This file was deleted.

src/librustc_mir/borrow_check/borrow_set.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,8 @@ impl<'a, 'gcx, 'tcx> GatherBorrows<'a, 'gcx, 'tcx> {
303303
/// allowed to be split into separate Reservation and
304304
/// Activation phases.
305305
fn allow_two_phase_borrow(&self, kind: mir::BorrowKind) -> bool {
306-
self.tcx.two_phase_borrows()
307-
&& (kind.allows_two_phase_borrow()
308-
|| self.tcx.sess.opts.debugging_opts.two_phase_beyond_autoref)
306+
kind.allows_two_phase_borrow()
307+
|| self.tcx.sess.opts.debugging_opts.two_phase_beyond_autoref
309308
}
310309

311310
/// If this is a two-phase borrow, then we will record it

0 commit comments

Comments
 (0)