Skip to content

Commit

Permalink
Use new Place::is_indirect API where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
ecstatic-morse committed Aug 30, 2019
1 parent 8648732 commit 96ac02b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
23 changes: 7 additions & 16 deletions src/librustc_mir/borrow_check/path_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::borrow_check::places_conflict;
use crate::borrow_check::AccessDepth;
use crate::dataflow::indexes::BorrowIndex;
use rustc::mir::{BasicBlock, Location, Body, Place, PlaceBase};
use rustc::mir::{ProjectionElem, BorrowKind};
use rustc::mir::BorrowKind;
use rustc::ty::{self, TyCtxt};
use rustc_data_structures::graph::dominators::Dominators;

Expand Down Expand Up @@ -133,20 +133,11 @@ pub(super) fn is_active<'tcx>(
/// Determines if a given borrow is borrowing local data
/// This is called for all Yield statements on movable generators
pub(super) fn borrow_of_local_data(place: &Place<'_>) -> bool {
place.iterate(|place_base, place_projection| {
match place_base {
PlaceBase::Static(..) => return false,
PlaceBase::Local(..) => {},
}

for proj in place_projection {
// Reborrow of already borrowed data is ignored
// Any errors will be caught on the initial borrow
if proj.elem == ProjectionElem::Deref {
return false;
}
}
match place.base {
PlaceBase::Static(_) => false,

true
})
// Reborrow of already borrowed data is ignored
// Any errors will be caught on the initial borrow
PlaceBase::Local(_) => !place.is_indirect(),
}
}
17 changes: 4 additions & 13 deletions src/librustc_mir/dataflow/impls/borrowed_locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,10 @@ struct BorrowedLocalsVisitor<'gk> {
}

fn find_local(place: &Place<'_>) -> Option<Local> {
place.iterate(|place_base, place_projection| {
for proj in place_projection {
if proj.elem == ProjectionElem::Deref {
return None;
}
}

if let PlaceBase::Local(local) = place_base {
Some(*local)
} else {
None
}
})
match place.base {
PlaceBase::Local(local) if !place.is_indirect() => Some(local),
_ => None,
}
}

impl<'tcx> Visitor<'tcx> for BorrowedLocalsVisitor<'_> {
Expand Down

0 comments on commit 96ac02b

Please sign in to comment.