From 2019d69f6158be1f2108c12264b2beb94af0aafe Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 19 Dec 2017 15:28:13 -0300 Subject: [PATCH] feature nll implies two-phase-borrows --- src/librustc/session/mod.rs | 3 +++ src/librustc_mir/borrow_check/mod.rs | 6 +++--- .../two-phase-control-flow-split-before-activation.rs | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 43ed9f02157..f897ba4df1d 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -443,6 +443,9 @@ impl Session { pub fn nll_dump_cause(&self) -> bool { self.opts.debugging_opts.nll_dump_cause } + pub fn two_phase_borrows(&self) -> bool { + self.features.borrow().nll || self.opts.debugging_opts.two_phase_borrows + } pub fn emit_end_regions(&self) -> bool { self.opts.debugging_opts.emit_end_regions || (self.opts.debugging_opts.mir_emit_validate > 0) || diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 34c91b84f28..b53e3e4c17a 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -774,7 +774,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { (Read(kind), BorrowKind::Unique) | (Read(kind), BorrowKind::Mut) => { // Reading from mere reservations of mutable-borrows is OK. - if this.tcx.sess.opts.debugging_opts.two_phase_borrows && index.is_reservation() + if this.tcx.sess.two_phase_borrows() && index.is_reservation() { return Control::Continue; } @@ -922,7 +922,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { BorrowKind::Shared => (Deep, Read(ReadKind::Borrow(bk))), BorrowKind::Unique | BorrowKind::Mut => { let wk = WriteKind::MutableBorrow(bk); - if self.tcx.sess.opts.debugging_opts.two_phase_borrows { + if self.tcx.sess.two_phase_borrows() { (Deep, Reservation(wk)) } else { (Deep, Write(wk)) @@ -1112,7 +1112,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { span: Span, flow_state: &Flows<'cx, 'gcx, 'tcx>, ) { - if !self.tcx.sess.opts.debugging_opts.two_phase_borrows { + if !self.tcx.sess.two_phase_borrows() { return; } diff --git a/src/test/run-pass/borrowck/two-phase-control-flow-split-before-activation.rs b/src/test/run-pass/borrowck/two-phase-control-flow-split-before-activation.rs index a891e6072a7..162314a8b79 100644 --- a/src/test/run-pass/borrowck/two-phase-control-flow-split-before-activation.rs +++ b/src/test/run-pass/borrowck/two-phase-control-flow-split-before-activation.rs @@ -10,7 +10,9 @@ // revisions: lxl nll //[lxl]compile-flags: -Z borrowck=mir -Z two-phase-borrows -//[nll]compile-flags: -Z borrowck=mir -Z two-phase-borrows -Z nll +//[nll]compile-flags: -Z borrowck=mir + +#![cfg_attr(nll, feature(nll))] fn main() { let mut a = 0;