Skip to content

Commit

Permalink
construct the BorrowSet outside of borrows
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Apr 15, 2018
1 parent e112367 commit 5f7b74f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use util::collect_writes::FindAssignments;

use std::iter;

use self::borrow_set::BorrowData;
use self::borrow_set::{BorrowSet, BorrowData};
use self::flows::Flows;
use self::prefixes::PrefixSet;
use self::MutateMode::{JustWrite, WriteAndRead};
Expand Down Expand Up @@ -192,6 +192,8 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
|bd, i| DebugFormatted::new(&bd.move_data().inits[i]),
));

let borrow_set = BorrowSet::build(tcx, mir);

// If we are in non-lexical mode, compute the non-lexical lifetimes.
let (opt_regioncx, opt_closure_req) = if let Some(free_regions) = free_regions {
let (regioncx, opt_closure_req) = nll::compute_regions(
Expand All @@ -216,7 +218,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
id,
&attributes,
&dead_unwinds,
Borrows::new(tcx, mir, opt_regioncx.clone(), def_id, body_id),
Borrows::new(tcx, mir, opt_regioncx.clone(), def_id, body_id, borrow_set),
|rs, i| {
DebugFormatted::new(&(i.kind(), rs.location(i.borrow_index())))
}
Expand Down
15 changes: 8 additions & 7 deletions src/librustc_mir/dataflow/impls/borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,18 @@ impl ReserveOrActivateIndex {
}

impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>,
mir: &'a Mir<'tcx>,
nonlexical_regioncx: Option<Rc<RegionInferenceContext<'tcx>>>,
def_id: DefId,
body_id: Option<hir::BodyId>)
-> Self {
crate fn new(
tcx: TyCtxt<'a, 'gcx, 'tcx>,
mir: &'a Mir<'tcx>,
nonlexical_regioncx: Option<Rc<RegionInferenceContext<'tcx>>>,
def_id: DefId,
body_id: Option<hir::BodyId>,
borrow_set: BorrowSet<'tcx>
) -> Self {
let scope_tree = tcx.region_scope_tree(def_id);
let root_scope = body_id.map(|body_id| {
region::Scope::CallSite(tcx.hir.body(body_id).value.hir_id.local_id)
});
let borrow_set = BorrowSet::build(tcx, mir);

Borrows {
tcx: tcx,
Expand Down
1 change: 0 additions & 1 deletion src/librustc_mir/dataflow/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ mod borrowed_locals;

pub use self::borrowed_locals::*;

#[allow(dead_code)]
pub(super) mod borrows;

/// `MaybeInitializedPlaces` tracks all places that might be
Expand Down

0 comments on commit 5f7b74f

Please sign in to comment.