]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/borrow_check/path_utils.rs
Changes the type `mir::Mir` into `mir::Body`
[rust.git] / src / librustc_mir / borrow_check / path_utils.rs
index 0c2a4ef45f104f3986d33da833a689eb1e30913c..557d235c23f0555b8ced991aa4b5b93d61f7edef 100644 (file)
@@ -2,7 +2,7 @@
 use crate::borrow_check::places_conflict;
 use crate::borrow_check::AccessDepth;
 use crate::dataflow::indexes::BorrowIndex;
-use rustc::mir::{BasicBlock, Location, Mir, Place, PlaceBase};
+use rustc::mir::{BasicBlock, Location, Body, Place, PlaceBase};
 use rustc::mir::{ProjectionElem, BorrowKind};
 use rustc::ty::TyCtxt;
 use rustc_data_structures::graph::dominators::Dominators;
@@ -25,7 +25,7 @@ pub(super) enum Control {
 pub(super) fn each_borrow_involving_path<'a, 'tcx, 'gcx: 'tcx, F, I, S> (
     s: &mut S,
     tcx: TyCtxt<'a, 'gcx, 'tcx>,
-    mir: &Mir<'tcx>,
+    mir: &Body<'tcx>,
     _location: Location,
     access_place: (AccessDepth, &Place<'tcx>),
     borrow_set: &BorrowSet<'tcx>,
@@ -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
+    })
 }