]> git.lizzy.rs Git - rust.git/commitdiff
Use new `Place::is_indirect` API where possible
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Thu, 29 Aug 2019 20:30:53 +0000 (13:30 -0700)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Fri, 30 Aug 2019 21:08:18 +0000 (14:08 -0700)
src/librustc_mir/borrow_check/path_utils.rs
src/librustc_mir/dataflow/impls/borrowed_locals.rs

index 43a012e1494f88e1df0a16c27cf7a4573f49510a..bac08090817d952d98ca59d7be60294a8d3f343c 100644 (file)
@@ -3,7 +3,7 @@
 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;
 
@@ -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(),
+    }
 }
index d94ebdbae24ae9f68d3a9468a431b1cdfd9f84c0..1c43a553cc3c9edc681224df761c7f19f1cabe24 100644 (file)
@@ -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<'_> {