]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/transform/promote_consts.rs
Merge branch 'master' into rusty-hermit
[rust.git] / src / librustc_mir / transform / promote_consts.rs
index 7d1b96b8be170dc89d11cde8d5194285a88cf723..ad1785417cd93409633603c784e9b8735143e92c 100644 (file)
@@ -20,7 +20,7 @@
 use rustc::ty::TyCtxt;
 use syntax_pos::Span;
 
-use rustc_data_structures::indexed_vec::{IndexVec, Idx};
+use rustc_index::vec::{IndexVec, Idx};
 
 use std::{iter, mem, usize};
 
@@ -191,6 +191,10 @@ fn assign(&mut self, dest: Local, rvalue: Rvalue<'tcx>, span: Span) {
         });
     }
 
+    fn is_temp_kind(&self, local: Local) -> bool {
+        self.source.local_kind(local) == LocalKind::Temp
+    }
+
     /// Copies the initialization of this temp to the
     /// promoted MIR, recursing through temps.
     fn promote_temp(&mut self, temp: Local) -> Local {
@@ -396,10 +400,22 @@ fn visit_local(&mut self,
                    local: &mut Local,
                    _: PlaceContext,
                    _: Location) {
-        if self.source.local_kind(*local) == LocalKind::Temp {
+        if self.is_temp_kind(*local) {
             *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>(