From 818ae6feceb4282193800c7e3668d3dfd2912378 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sat, 7 Apr 2018 08:20:24 -0400 Subject: [PATCH] don't expose the `borrows` field --- src/librustc_mir/borrow_check/flows.rs | 16 +++++++++++++--- src/librustc_mir/borrow_check/mod.rs | 13 ++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/librustc_mir/borrow_check/flows.rs b/src/librustc_mir/borrow_check/flows.rs index b5cfdee6a454c..070dc1d09bf6b 100644 --- a/src/librustc_mir/borrow_check/flows.rs +++ b/src/librustc_mir/borrow_check/flows.rs @@ -14,17 +14,19 @@ //! but is not as ugly as it is right now. use rustc::mir::{BasicBlock, Location}; +use rustc_data_structures::indexed_set::Iter; use dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces}; use dataflow::{EverInitializedPlaces, MovingOutStatements}; use dataflow::{Borrows}; use dataflow::{FlowAtLocation, FlowsAtLocation}; use dataflow::move_paths::HasMoveData; +use dataflow::move_paths::indexes::BorrowIndex; use std::fmt; // (forced to be `pub` due to its use as an associated type below.) -pub(crate) struct Flows<'b, 'gcx: 'tcx, 'tcx: 'b> { - pub borrows: FlowAtLocation>, +crate struct Flows<'b, 'gcx: 'tcx, 'tcx: 'b> { + borrows: FlowAtLocation>, pub inits: FlowAtLocation>, pub uninits: FlowAtLocation>, pub move_outs: FlowAtLocation>, @@ -32,7 +34,7 @@ pub(crate) struct Flows<'b, 'gcx: 'tcx, 'tcx: 'b> { } impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> { - pub fn new( + crate fn new( borrows: FlowAtLocation>, inits: FlowAtLocation>, uninits: FlowAtLocation>, @@ -47,6 +49,14 @@ impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> { ever_inits, } } + + crate fn borrows_in_scope(&self) -> impl Iterator + '_ { + self.borrows.iter_incoming() + } + + crate fn with_outgoing_borrows(&self, op: impl FnOnce(Iter)) { + self.borrows.with_iter_outgoing(op) + } } macro_rules! each_flow { diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 40af0c0b18d0c..5b4c66bd65c17 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -550,7 +550,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx if self.movable_generator { // Look for any active borrows to locals let borrow_set = self.borrow_set.clone(); - flow_state.borrows.with_iter_outgoing(|borrows| { + flow_state.with_outgoing_borrows(|borrows| { for i in borrows { let borrow = &borrow_set[i]; self.check_for_local_borrow(borrow, span); @@ -565,7 +565,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx // StorageDead, but we don't always emit those (notably on unwind paths), // so this "extra check" serves as a kind of backup. let borrow_set = self.borrow_set.clone(); - flow_state.borrows.with_iter_outgoing(|borrows| { + flow_state.with_outgoing_borrows(|borrows| { for i in borrows { let borrow = &borrow_set[i]; let context = ContextKind::StorageDead.new(loc); @@ -2224,10 +2224,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { unreachable!("iter::repeat returned None") } - /// This function iterates over all of the current borrows - /// (represented by 1-bits in `flow_state.borrows`) that conflict - /// with an access to a place, invoking the `op` callback for each - /// one. + /// This function iterates over all of the in-scope borrows that + /// conflict with an access to a place, invoking the `op` callback + /// for each one. /// /// "Current borrow" here means a borrow that reaches the point in /// the control-flow where the access occurs. @@ -2251,7 +2250,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { // check for loan restricting path P being used. Accounts for // borrows of P, P.a.b, etc. let borrow_set = self.borrow_set.clone(); - for i in flow_state.borrows.iter_incoming() { + for i in flow_state.borrows_in_scope() { let borrowed = &borrow_set[i]; if self.places_conflict(&borrowed.borrowed_place, place, access) {