diff options
| author | Santiago Pastorino <spastorino@gmail.com> | 2019-05-23 21:43:21 +0200 |
|---|---|---|
| committer | Santiago Pastorino <spastorino@gmail.com> | 2019-05-24 18:42:04 +0200 |
| commit | 96137798556e662e9bb744fb58055e06147b9330 (patch) | |
| tree | 563434cfc8650e6b21615d911ad6d9c3325fff5a | |
| parent | 27cc0db7a248308fc2634ac68d7608a20b4a1c09 (diff) | |
| download | rust-96137798556e662e9bb744fb58055e06147b9330.tar.gz rust-96137798556e662e9bb744fb58055e06147b9330.zip | |
Make borrow_of_local_data iterate instead of recurse
| -rw-r--r-- | src/librustc_mir/borrow_check/path_utils.rs | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/librustc_mir/borrow_check/path_utils.rs b/src/librustc_mir/borrow_check/path_utils.rs index 0c2a4ef45f1..caef8d8bc5a 100644 --- a/src/librustc_mir/borrow_check/path_utils.rs +++ b/src/librustc_mir/borrow_check/path_utils.rs @@ -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 + }) } |
