Skip to content

Commit 5dbc0f0

Browse files
committed
Enable migrate mode by default on the 2015 edition
This also fully stabilizes two-phase borrows on all editions
1 parent de5c3c4 commit 5dbc0f0

File tree

16 files changed

+151
-355
lines changed

16 files changed

+151
-355
lines changed

src/librustc/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl SuppressRegionErrors {
9393
pub fn when_nll_is_enabled(tcx: TyCtxt<'_, '_, '_>) -> Self {
9494
match tcx.borrowck_mode() {
9595
// If we're on AST or Migrate mode, report AST region errors
96-
BorrowckMode::Ast | BorrowckMode::Migrate => SuppressRegionErrors { suppressed: false },
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
@@ -437,7 +437,6 @@ pub enum PrintRequest {
437437

438438
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
439439
pub enum BorrowckMode {
440-
Ast,
441440
Mir,
442441
Compare,
443442
Migrate,
@@ -448,7 +447,6 @@ impl BorrowckMode {
448447
/// on the AST borrow check if the MIR-based one errors.
449448
pub fn migrate(self) -> bool {
450449
match self {
451-
BorrowckMode::Ast => false,
452450
BorrowckMode::Compare => false,
453451
BorrowckMode::Mir => false,
454452
BorrowckMode::Migrate => true,
@@ -458,21 +456,11 @@ impl BorrowckMode {
458456
/// Should we emit the AST-based borrow checker errors?
459457
pub fn use_ast(self) -> bool {
460458
match self {
461-
BorrowckMode::Ast => true,
462459
BorrowckMode::Compare => true,
463460
BorrowckMode::Mir => false,
464461
BorrowckMode::Migrate => false,
465462
}
466463
}
467-
/// Should we emit the MIR-based borrow checker errors?
468-
pub fn use_mir(self) -> bool {
469-
match self {
470-
BorrowckMode::Ast => false,
471-
BorrowckMode::Compare => true,
472-
BorrowckMode::Mir => true,
473-
BorrowckMode::Migrate => true,
474-
}
475-
}
476464
}
477465

478466
pub enum Input {
@@ -604,7 +592,7 @@ impl Default for Options {
604592
incremental: None,
605593
debugging_opts: basic_debugging_options(),
606594
prints: Vec::new(),
607-
borrowck_mode: BorrowckMode::Ast,
595+
borrowck_mode: BorrowckMode::Migrate,
608596
cg: basic_codegen_options(),
609597
error_format: ErrorOutputType::default(),
610598
externs: Externs(BTreeMap::new()),
@@ -2250,10 +2238,9 @@ pub fn build_session_options_and_crate_config(
22502238
}));
22512239

22522240
let borrowck_mode = match debugging_opts.borrowck.as_ref().map(|s| &s[..]) {
2253-
None | Some("ast") => BorrowckMode::Ast,
2241+
None | Some("migrate") => BorrowckMode::Migrate,
22542242
Some("mir") => BorrowckMode::Mir,
22552243
Some("compare") => BorrowckMode::Compare,
2256-
Some("migrate") => BorrowckMode::Migrate,
22572244
Some(m) => early_error(error_format, &format!("unknown borrowck mode `{}`", m)),
22582245
};
22592246

src/librustc/ty/context.rs

+7-53
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ use rustc_target::spec::abi;
6868
use syntax::ast;
6969
use syntax::attr;
7070
use syntax::source_map::MultiSpan;
71-
use syntax::edition::Edition;
7271
use syntax::feature_gate;
7372
use syntax::symbol::{Symbol, keywords, InternedString};
7473
use syntax_pos::Span;
@@ -1472,21 +1471,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
14721471
/// because that method has a narrower effect that can be toggled
14731472
/// off via a separate `-Z` flag, at least for the short term.
14741473
pub fn allow_bind_by_move_patterns_with_guards(self) -> bool {
1475-
self.features().bind_by_move_pattern_guards && self.use_mir_borrowck()
1474+
self.features().bind_by_move_pattern_guards
14761475
}
14771476

14781477
/// If true, we should use a naive AST walk to determine if match
14791478
/// guard could perform bad mutations (or mutable-borrows).
14801479
pub fn check_for_mutation_in_guard_via_ast_walk(self) -> bool {
1481-
// If someone requests the feature, then be a little more
1482-
// careful and ensure that MIR-borrowck is enabled (which can
1483-
// happen via edition selection, via `feature(nll)`, or via an
1484-
// appropriate `-Z` flag) before disabling the mutation check.
1485-
if self.allow_bind_by_move_patterns_with_guards() {
1486-
return false;
1487-
}
1488-
1489-
return true;
1480+
!self.allow_bind_by_move_patterns_with_guards()
14901481
}
14911482

14921483
/// If true, we should use the AST-based borrowck (we may *also* use
@@ -1495,12 +1486,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
14951486
self.borrowck_mode().use_ast()
14961487
}
14971488

1498-
/// If true, we should use the MIR-based borrowck (we may *also* use
1499-
/// the AST-based borrowck).
1500-
pub fn use_mir_borrowck(self) -> bool {
1501-
self.borrowck_mode().use_mir()
1502-
}
1503-
15041489
/// If true, we should use the MIR-based borrow check, but also
15051490
/// fall back on the AST borrow check if the MIR-based one errors.
15061491
pub fn migrate_borrowck(self) -> bool {
@@ -1517,38 +1502,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
15171502
/// statements (which simulate the maximal effect of executing the
15181503
/// patterns in a match arm).
15191504
pub fn emit_read_for_match(&self) -> bool {
1520-
self.use_mir_borrowck() && !self.sess.opts.debugging_opts.nll_dont_emit_read_for_match
1521-
}
1522-
1523-
/// If true, pattern variables for use in guards on match arms
1524-
/// will be bound as references to the data, and occurrences of
1525-
/// those variables in the guard expression will implicitly
1526-
/// dereference those bindings. (See rust-lang/rust#27282.)
1527-
pub fn all_pat_vars_are_implicit_refs_within_guards(self) -> bool {
1528-
self.borrowck_mode().use_mir()
1529-
}
1530-
1531-
/// If true, we should enable two-phase borrows checks. This is
1532-
/// done with either: `-Ztwo-phase-borrows`, `#![feature(nll)]`,
1533-
/// or by opting into an edition after 2015.
1534-
pub fn two_phase_borrows(self) -> bool {
1535-
self.sess.rust_2018() || self.features().nll ||
1536-
self.sess.opts.debugging_opts.two_phase_borrows
1505+
!self.sess.opts.debugging_opts.nll_dont_emit_read_for_match
15371506
}
15381507

15391508
/// What mode(s) of borrowck should we run? AST? MIR? both?
15401509
/// (Also considers the `#![feature(nll)]` setting.)
15411510
pub fn borrowck_mode(&self) -> BorrowckMode {
15421511
// Here are the main constraints we need to deal with:
15431512
//
1544-
// 1. An opts.borrowck_mode of `BorrowckMode::Ast` is
1513+
// 1. An opts.borrowck_mode of `BorrowckMode::Migrate` is
15451514
// synonymous with no `-Z borrowck=...` flag at all.
1546-
// (This is arguably a historical accident.)
1547-
//
1548-
// 2. `BorrowckMode::Migrate` is the limited migration to
1549-
// NLL that we are deploying with the 2018 edition.
15501515
//
1551-
// 3. We want to allow developers on the Nightly channel
1516+
// 2. We want to allow developers on the Nightly channel
15521517
// to opt back into the "hard error" mode for NLL,
15531518
// (which they can do via specifying `#![feature(nll)]`
15541519
// explicitly in their crate).
@@ -1561,24 +1526,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
15611526
// a user's attempt to specify `-Z borrowck=compare`, which
15621527
// we arguably do not need anymore and should remove.)
15631528
//
1564-
// * Otherwise, if no `-Z borrowck=...` flag was given (or
1565-
// if `borrowck=ast` was specified), then use the default
1566-
// as required by the edition.
1529+
// * Otherwise, if no `-Z borrowck=...` then use migrate mode
15671530
//
15681531
// * Otherwise, use the behavior requested via `-Z borrowck=...`
15691532

15701533
if self.features().nll { return BorrowckMode::Mir; }
15711534

1572-
match self.sess.opts.borrowck_mode {
1573-
mode @ BorrowckMode::Mir |
1574-
mode @ BorrowckMode::Compare |
1575-
mode @ BorrowckMode::Migrate => mode,
1576-
1577-
BorrowckMode::Ast => match self.sess.edition() {
1578-
Edition::Edition2015 => BorrowckMode::Ast,
1579-
Edition::Edition2018 => BorrowckMode::Migrate,
1580-
},
1581-
}
1535+
self.sess.opts.borrowck_mode
15821536
}
15831537

15841538
#[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

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

142-
if !tcx.use_mir_borrowck() {
143-
unused::check(&mut bccx, body);
144-
}
145-
146140
Lrc::new(BorrowCheckResult {
147141
used_mut_nodes: bccx.used_mut_nodes.into_inner(),
148142
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)