diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2018-04-07 08:20:24 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2018-04-15 07:06:30 -0400 |
| commit | 818ae6feceb4282193800c7e3668d3dfd2912378 (patch) | |
| tree | 8eab5a3187372abb5f9ea2187ad639ca68a569c3 /src | |
| parent | 033c4f2e3c43999e47f543f569dad181ec590b22 (diff) | |
don't expose the `borrows` field
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/borrow_check/flows.rs | 16 | ||||
| -rw-r--r-- | 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 b5cfdee6a45..070dc1d09bf 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<Borrows<'b, 'gcx, 'tcx>>, +crate struct Flows<'b, 'gcx: 'tcx, 'tcx: 'b> { + borrows: FlowAtLocation<Borrows<'b, 'gcx, 'tcx>>, pub inits: FlowAtLocation<MaybeInitializedPlaces<'b, 'gcx, 'tcx>>, pub uninits: FlowAtLocation<MaybeUninitializedPlaces<'b, 'gcx, 'tcx>>, pub move_outs: FlowAtLocation<MovingOutStatements<'b, 'gcx, 'tcx>>, @@ -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<Borrows<'b, 'gcx, 'tcx>>, inits: FlowAtLocation<MaybeInitializedPlaces<'b, 'gcx, 'tcx>>, uninits: FlowAtLocation<MaybeUninitializedPlaces<'b, 'gcx, 'tcx>>, @@ -47,6 +49,14 @@ impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> { ever_inits, } } + + crate fn borrows_in_scope(&self) -> impl Iterator<Item = BorrowIndex> + '_ { + self.borrows.iter_incoming() + } + + crate fn with_outgoing_borrows(&self, op: impl FnOnce(Iter<BorrowIndex>)) { + 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 40af0c0b18d..5b4c66bd65c 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) { |
