]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_mir/src/dataflow/move_paths/builder.rs
Use PlaceRef more consistently in rustc_mir
[rust.git] / compiler / rustc_mir / src / dataflow / move_paths / builder.rs
index 5c3e3538401801993de42ebe832fdd8423fba66b..ee78ff00c9b2baa022045ee9a5db2483bbe7fac9 100644 (file)
@@ -362,17 +362,18 @@ fn gather_rvalue(&mut self, rvalue: &Rvalue<'tcx>) {
     fn gather_terminator(&mut self, term: &Terminator<'tcx>) {
         match term.kind {
             TerminatorKind::Goto { target: _ }
+            | TerminatorKind::FalseEdge { .. }
+            | TerminatorKind::FalseUnwind { .. }
+            // In some sense returning moves the return place into the current
+            // call's destination, however, since there are no statements after
+            // this that could possibly access the return place, this doesn't
+            // need recording.
+            | TerminatorKind::Return
             | TerminatorKind::Resume
             | TerminatorKind::Abort
             | TerminatorKind::GeneratorDrop
-            | TerminatorKind::FalseEdge { .. }
-            | TerminatorKind::FalseUnwind { .. }
             | TerminatorKind::Unreachable => {}
 
-            TerminatorKind::Return => {
-                self.gather_move(Place::return_place());
-            }
-
             TerminatorKind::Assert { ref cond, .. } => {
                 self.gather_operand(cond);
             }
@@ -517,14 +518,10 @@ fn gather_init(&mut self, place: PlaceRef<'tcx>, kind: InitKind) {
 
         // Check if we are assigning into a field of a union, if so, lookup the place
         // of the union so it is marked as initialized again.
-        if let [proj_base @ .., ProjectionElem::Field(_, _)] = place.projection {
-            if let ty::Adt(def, _) =
-                Place::ty_from(place.local, proj_base, self.builder.body, self.builder.tcx)
-                    .ty
-                    .kind()
-            {
+        if let Some((place_base, ProjectionElem::Field(_, _))) = place.last_projection() {
+            if let ty::Adt(def, _) = place_base.ty(self.builder.body, self.builder.tcx).ty.kind() {
                 if def.is_union() {
-                    place = PlaceRef { local: place.local, projection: proj_base }
+                    place = place_base;
                 }
             }
         }