Skip to content

Commit

Permalink
Make borrow_of_local_data iterate instead of recurse
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed May 24, 2019
1 parent 27cc0db commit 9613779
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/librustc_mir/borrow_check/path_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,20 @@ 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<'tcx>(place: &Place<'tcx>) -> bool {
match place {
Place::Base(PlaceBase::Static(..)) => false,
Place::Base(PlaceBase::Local(..)) => true,
Place::Projection(box proj) => {
match proj.elem {
// Reborrow of already borrowed data is ignored
// Any errors will be caught on the initial borrow
ProjectionElem::Deref => false,
place.iterate(|place_base, place_projection| {
match place_base {
PlaceBase::Static(..) => return false,
PlaceBase::Local(..) => {},
}

// For interior references and downcasts, find out if the base is local
ProjectionElem::Field(..)
| ProjectionElem::Index(..)
| ProjectionElem::ConstantIndex { .. }
| ProjectionElem::Subslice { .. }
| ProjectionElem::Downcast(..) => borrow_of_local_data(&proj.base),
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;
}
}
}

true
})
}

0 comments on commit 9613779

Please sign in to comment.