X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;ds=sidebyside;f=src%2Flibrustc_mir%2Ftransform%2Fpromote_consts.rs;h=ad1785417cd93409633603c784e9b8735143e92c;hb=b6801b7dcd56a272dda2fbd88ecbc5b1476d8b83;hp=7d1b96b8be170dc89d11cde8d5194285a88cf723;hpb=b30238e3125a6c1ebf95cf47e58566efc75ad2f1;p=rust.git diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 7d1b96b8be1..ad1785417cd 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -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> { + match elem { + PlaceElem::Index(local) if self.is_temp_kind(*local) => { + Some(PlaceElem::Index(self.promote_temp(*local))) + } + _ => None, + } + } } pub fn promote_candidates<'tcx>(