]> git.lizzy.rs Git - rust.git/commitdiff
Pass the `PlaceElem::Index` local to `visit_local`
authorJonas Schievink <jonasschievink@gmail.com>
Fri, 10 Apr 2020 23:39:50 +0000 (01:39 +0200)
committerJonas Schievink <jonasschievink@gmail.com>
Fri, 10 Apr 2020 23:39:50 +0000 (01:39 +0200)
src/librustc_middle/mir/visit.rs
src/librustc_mir/borrow_check/renumber.rs
src/librustc_mir/transform/generator.rs
src/librustc_mir/transform/inline.rs
src/librustc_mir/transform/promote_consts.rs
src/librustc_mir/transform/simplify.rs
src/librustc_mir/util/def_use.rs

index 400d15cdc144be6518cc338adee383a6b64eb8f5..5c33db299ae8575939a27331c71d2579fb90cd6c 100644 (file)
@@ -838,7 +838,7 @@ fn visit_location(
 }
 
 macro_rules! visit_place_fns {
-    (mut) => (
+    (mut) => {
         fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;
 
         fn super_place(
@@ -849,7 +849,7 @@ fn super_place(
         ) {
             self.visit_place_base(&mut place.local, context, location);
 
-            if let Some(new_projection) = self.process_projection(&place.projection) {
+            if let Some(new_projection) = self.process_projection(&place.projection, location) {
                 place.projection = self.tcx().intern_place_elems(&new_projection);
             }
         }
@@ -857,12 +857,13 @@ fn super_place(
         fn process_projection(
             &mut self,
             projection: &'a [PlaceElem<'tcx>],
+            location: Location,
         ) -> Option<Vec<PlaceElem<'tcx>>> {
             let mut projection = Cow::Borrowed(projection);
 
             for i in 0..projection.len() {
                 if let Some(elem) = projection.get(i) {
-                    if let Some(elem) = self.process_projection_elem(elem) {
+                    if let Some(elem) = self.process_projection_elem(elem, location) {
                         // This converts the borrowed projection into `Cow::Owned(_)` and returns a
                         // clone of the projection so we can mutate and reintern later.
                         let vec = projection.to_mut();
@@ -879,13 +880,30 @@ fn process_projection(
 
         fn process_projection_elem(
             &mut self,
-            _elem: &PlaceElem<'tcx>,
+            elem: &PlaceElem<'tcx>,
+            location: Location,
         ) -> Option<PlaceElem<'tcx>> {
-            None
+            match elem {
+                PlaceElem::Index(local) => {
+                    let mut new_local = *local;
+                    self.visit_local(
+                        &mut new_local,
+                        PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
+                        location,
+                    );
+
+                    if new_local == *local { None } else { Some(PlaceElem::Index(new_local)) }
+                }
+                PlaceElem::Deref
+                | PlaceElem::Field(..)
+                | PlaceElem::ConstantIndex { .. }
+                | PlaceElem::Subslice { .. }
+                | PlaceElem::Downcast(..) => None,
+            }
         }
-    );
+    };
 
-    () => (
+    () => {
         fn visit_projection(
             &mut self,
             local: Local,
@@ -907,12 +925,7 @@ fn visit_projection_elem(
             self.super_projection_elem(local, proj_base, elem, context, location);
         }
 
-        fn super_place(
-            &mut self,
-            place: &Place<'tcx>,
-            context: PlaceContext,
-            location: Location,
-        ) {
+        fn super_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: Location) {
             let mut context = context;
 
             if !place.projection.is_empty() {
@@ -925,10 +938,7 @@ fn super_place(
 
             self.visit_place_base(&place.local, context, location);
 
-            self.visit_projection(place.local,
-                                  &place.projection,
-                                  context,
-                                  location);
+            self.visit_projection(place.local, &place.projection, context, location);
         }
 
         fn super_projection(
@@ -961,19 +971,16 @@ fn super_projection_elem(
                     self.visit_local(
                         local,
                         PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
-                        location
+                        location,
                     );
                 }
-                ProjectionElem::Deref |
-                ProjectionElem::Subslice { from: _, to: _, from_end: _ } |
-                ProjectionElem::ConstantIndex { offset: _,
-                                                min_length: _,
-                                                from_end: _ } |
-                ProjectionElem::Downcast(_, _) => {
-                }
+                ProjectionElem::Deref
+                | ProjectionElem::Subslice { from: _, to: _, from_end: _ }
+                | ProjectionElem::ConstantIndex { offset: _, min_length: _, from_end: _ }
+                | ProjectionElem::Downcast(_, _) => {}
             }
         }
-    );
+    };
 }
 
 make_mir_visitor!(Visitor,);
index a1d7bc1462f95c2f6eb459e3bd9026c075867353..a6b4aa74977224b115cc4b1e40e2c0e7807c0921 100644 (file)
@@ -64,7 +64,11 @@ fn visit_ty(&mut self, ty: &mut Ty<'tcx>, ty_context: TyContext) {
         debug!("visit_ty: ty={:?}", ty);
     }
 
-    fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
+    fn process_projection_elem(
+        &mut self,
+        elem: &PlaceElem<'tcx>,
+        _: Location,
+    ) -> Option<PlaceElem<'tcx>> {
         if let PlaceElem::Field(field, ty) = elem {
             let new_ty = self.renumber_regions(ty);
 
index d25fd8ebb0c2bea75c73acac407a88ff3071539b..bc3c20d9f409a914709f4fcee9419e93ef86e355 100644 (file)
@@ -89,13 +89,6 @@ fn visit_local(&mut self, local: &mut Local, _: PlaceContext, _: Location) {
             *local = self.to;
         }
     }
-
-    fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
-        match elem {
-            PlaceElem::Index(local) if *local == self.from => Some(PlaceElem::Index(self.to)),
-            _ => None,
-        }
-    }
 }
 
 struct DerefArgVisitor<'tcx> {
index 157dada831a2e2610b5d304988c00241cd8fcb5c..8121d4ead13943dfd5c0fc543cc2ff661802d765 100644 (file)
@@ -706,18 +706,6 @@ fn visit_place(&mut self, place: &mut Place<'tcx>, context: PlaceContext, locati
         self.super_place(place, context, location)
     }
 
-    fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
-        if let PlaceElem::Index(local) = elem {
-            let new_local = self.make_integrate_local(*local);
-
-            if new_local != *local {
-                return Some(PlaceElem::Index(new_local));
-            }
-        }
-
-        None
-    }
-
     fn visit_basic_block_data(&mut self, block: BasicBlock, data: &mut BasicBlockData<'tcx>) {
         self.in_cleanup_block = data.is_cleanup;
         self.super_basic_block_data(block, data);
index ec0b89ebb4d0aa7a8194a314312b7434f1eab7e5..9579fe1f405ba4368d790fc84ed131b124a5811d 100644 (file)
@@ -1036,15 +1036,6 @@ fn visit_local(&mut self, local: &mut Local, _: PlaceContext, _: Location) {
             *local = self.promote_temp(*local);
         }
     }
-
-    fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
-        match elem {
-            PlaceElem::Index(local) if self.is_temp_kind(*local) => {
-                Some(PlaceElem::Index(self.promote_temp(*local)))
-            }
-            _ => None,
-        }
-    }
 }
 
 pub fn promote_candidates<'tcx>(
index c2029a223b94123e3ec6a625cb83c15d58ac9195..c0da2c446d65fa30c81654a392f7aa2c82b85d35 100644 (file)
@@ -417,11 +417,4 @@ fn visit_basic_block_data(&mut self, block: BasicBlock, data: &mut BasicBlockDat
     fn visit_local(&mut self, l: &mut Local, _: PlaceContext, _: Location) {
         *l = self.map[*l].unwrap();
     }
-
-    fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
-        match elem {
-            PlaceElem::Index(local) => Some(PlaceElem::Index(self.map[*local].unwrap())),
-            _ => None,
-        }
-    }
 }
index 6b5f6aa991c1ea1306dfdc94a61a89e79118591f..0ac743359be96e2c91efbf06c25bd3fa6f718e7b 100644 (file)
@@ -2,9 +2,7 @@
 
 use rustc_index::vec::IndexVec;
 use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor};
-use rustc_middle::mir::{
-    Body, BodyAndCache, Local, Location, PlaceElem, ReadOnlyBodyAndCache, VarDebugInfo,
-};
+use rustc_middle::mir::{Body, BodyAndCache, Local, Location, ReadOnlyBodyAndCache, VarDebugInfo};
 use rustc_middle::ty::TyCtxt;
 use std::mem;
 
@@ -157,13 +155,4 @@ fn visit_local(&mut self, local: &mut Local, _context: PlaceContext, _location:
             *local = self.new_local;
         }
     }
-
-    fn process_projection_elem(&mut self, elem: &PlaceElem<'tcx>) -> Option<PlaceElem<'tcx>> {
-        match elem {
-            PlaceElem::Index(local) if *local == self.query => {
-                Some(PlaceElem::Index(self.new_local))
-            }
-            _ => None,
-        }
-    }
 }