don't expose the borrows field

This commit is contained in:
Niko Matsakis 2018-04-07 08:20:24 -04:00
parent 033c4f2e3c
commit 818ae6fece
2 changed files with 19 additions and 10 deletions

View file

@ -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 {

View file

@ -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) {