Skip to content

Commit 314f951

Browse files
committed
don't expose the borrows field
1 parent 4ef0c11 commit 314f951

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/librustc_mir/borrow_check/flows.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,27 @@
1414
//! but is not as ugly as it is right now.
1515
1616
use rustc::mir::{BasicBlock, Location};
17+
use rustc_data_structures::indexed_set::Iter;
1718

1819
use dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces};
1920
use dataflow::{EverInitializedPlaces, MovingOutStatements};
2021
use dataflow::{Borrows};
2122
use dataflow::{FlowAtLocation, FlowsAtLocation};
2223
use dataflow::move_paths::HasMoveData;
24+
use dataflow::move_paths::indexes::BorrowIndex;
2325
use std::fmt;
2426

2527
// (forced to be `pub` due to its use as an associated type below.)
26-
pub(crate) struct Flows<'b, 'gcx: 'tcx, 'tcx: 'b> {
27-
pub borrows: FlowAtLocation<Borrows<'b, 'gcx, 'tcx>>,
28+
crate struct Flows<'b, 'gcx: 'tcx, 'tcx: 'b> {
29+
borrows: FlowAtLocation<Borrows<'b, 'gcx, 'tcx>>,
2830
pub inits: FlowAtLocation<MaybeInitializedPlaces<'b, 'gcx, 'tcx>>,
2931
pub uninits: FlowAtLocation<MaybeUninitializedPlaces<'b, 'gcx, 'tcx>>,
3032
pub move_outs: FlowAtLocation<MovingOutStatements<'b, 'gcx, 'tcx>>,
3133
pub ever_inits: FlowAtLocation<EverInitializedPlaces<'b, 'gcx, 'tcx>>,
3234
}
3335

3436
impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> {
35-
pub fn new(
37+
crate fn new(
3638
borrows: FlowAtLocation<Borrows<'b, 'gcx, 'tcx>>,
3739
inits: FlowAtLocation<MaybeInitializedPlaces<'b, 'gcx, 'tcx>>,
3840
uninits: FlowAtLocation<MaybeUninitializedPlaces<'b, 'gcx, 'tcx>>,
@@ -47,6 +49,14 @@ impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> {
4749
ever_inits,
4850
}
4951
}
52+
53+
crate fn borrows_in_scope(&self) -> impl Iterator<Item = BorrowIndex> + '_ {
54+
self.borrows.iter_incoming()
55+
}
56+
57+
crate fn with_outgoing_borrows(&self, op: impl FnOnce(Iter<BorrowIndex>)) {
58+
self.borrows.with_iter_outgoing(op)
59+
}
5060
}
5161

5262
macro_rules! each_flow {

src/librustc_mir/borrow_check/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
549549
if self.movable_generator {
550550
// Look for any active borrows to locals
551551
let borrow_set = self.borrow_set.clone();
552-
flow_state.borrows.with_iter_outgoing(|borrows| {
552+
flow_state.with_outgoing_borrows(|borrows| {
553553
for i in borrows {
554554
let borrow = &borrow_set[i];
555555
self.check_for_local_borrow(borrow, span);
@@ -564,7 +564,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
564564
// StorageDead, but we don't always emit those (notably on unwind paths),
565565
// so this "extra check" serves as a kind of backup.
566566
let borrow_set = self.borrow_set.clone();
567-
flow_state.borrows.with_iter_outgoing(|borrows| {
567+
flow_state.with_outgoing_borrows(|borrows| {
568568
for i in borrows {
569569
let borrow = &borrow_set[i];
570570
let context = ContextKind::StorageDead.new(loc);
@@ -2168,10 +2168,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
21682168
unreachable!("iter::repeat returned None")
21692169
}
21702170

2171-
/// This function iterates over all of the current borrows
2172-
/// (represented by 1-bits in `flow_state.borrows`) that conflict
2173-
/// with an access to a place, invoking the `op` callback for each
2174-
/// one.
2171+
/// This function iterates over all of the in-scope borrows that
2172+
/// conflict with an access to a place, invoking the `op` callback
2173+
/// for each one.
21752174
///
21762175
/// "Current borrow" here means a borrow that reaches the point in
21772176
/// the control-flow where the access occurs.
@@ -2195,7 +2194,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
21952194
// check for loan restricting path P being used. Accounts for
21962195
// borrows of P, P.a.b, etc.
21972196
let borrow_set = self.borrow_set.clone();
2198-
for i in flow_state.borrows.iter_incoming() {
2197+
for i in flow_state.borrows_in_scope() {
21992198
let borrowed = &borrow_set[i];
22002199

22012200
if self.places_conflict(&borrowed.borrowed_place, place, access) {

0 commit comments

Comments
 (0)