Skip to content

Commit 818ae6f

Browse files
committed
don't expose the borrows field
1 parent 033c4f2 commit 818ae6f

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/librustc_mir/borrow_check/flows.rs

+13-3
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

+6-7
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
550550
if self.movable_generator {
551551
// Look for any active borrows to locals
552552
let borrow_set = self.borrow_set.clone();
553-
flow_state.borrows.with_iter_outgoing(|borrows| {
553+
flow_state.with_outgoing_borrows(|borrows| {
554554
for i in borrows {
555555
let borrow = &borrow_set[i];
556556
self.check_for_local_borrow(borrow, span);
@@ -565,7 +565,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
565565
// StorageDead, but we don't always emit those (notably on unwind paths),
566566
// so this "extra check" serves as a kind of backup.
567567
let borrow_set = self.borrow_set.clone();
568-
flow_state.borrows.with_iter_outgoing(|borrows| {
568+
flow_state.with_outgoing_borrows(|borrows| {
569569
for i in borrows {
570570
let borrow = &borrow_set[i];
571571
let context = ContextKind::StorageDead.new(loc);
@@ -2224,10 +2224,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
22242224
unreachable!("iter::repeat returned None")
22252225
}
22262226

2227-
/// This function iterates over all of the current borrows
2228-
/// (represented by 1-bits in `flow_state.borrows`) that conflict
2229-
/// with an access to a place, invoking the `op` callback for each
2230-
/// one.
2227+
/// This function iterates over all of the in-scope borrows that
2228+
/// conflict with an access to a place, invoking the `op` callback
2229+
/// for each one.
22312230
///
22322231
/// "Current borrow" here means a borrow that reaches the point in
22332232
/// the control-flow where the access occurs.
@@ -2251,7 +2250,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
22512250
// check for loan restricting path P being used. Accounts for
22522251
// borrows of P, P.a.b, etc.
22532252
let borrow_set = self.borrow_set.clone();
2254-
for i in flow_state.borrows.iter_incoming() {
2253+
for i in flow_state.borrows_in_scope() {
22552254
let borrowed = &borrow_set[i];
22562255

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

0 commit comments

Comments
 (0)