diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 0fb43c7f98d..c8a6367899b 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -786,10 +786,32 @@ macro_rules! visit_place_fns { (mut) => ( fn super_place( &mut self, - _place: &mut Place<'tcx>, - _context: PlaceContext, - _location: Location, + place: &mut Place<'tcx>, + context: PlaceContext, + location: Location, ) { + self.visit_place_base(&mut place.base, context, location); + + place.projection = self.process_projection(&place.projection); + } + + fn process_projection( + &mut self, + projection: &Box<[PlaceElem<'tcx>]>, + ) -> Box<[PlaceElem<'tcx>]> { + let new_projection: Vec<_> = projection.iter().map(|elem| + self.process_projection_elem(elem) + ).collect(); + + new_projection.into_boxed_slice() + } + + fn process_projection_elem( + &mut self, + elem: &PlaceElem<'tcx>, + ) -> PlaceElem<'tcx> { + // FIXME: avoid cloning here + elem.clone() } ); diff --git a/src/librustc_mir/borrow_check/nll/renumber.rs b/src/librustc_mir/borrow_check/nll/renumber.rs index 6eb5735cb16..c4a19ce5128 100644 --- a/src/librustc_mir/borrow_check/nll/renumber.rs +++ b/src/librustc_mir/borrow_check/nll/renumber.rs @@ -1,7 +1,7 @@ use rustc::ty::subst::SubstsRef; use rustc::ty::{self, Ty, TypeFoldable}; -use rustc::mir::{Body, Location, Place, PlaceElem, Promoted}; -use rustc::mir::visit::{MutVisitor, PlaceContext, TyContext}; +use rustc::mir::{Body, Location, PlaceElem, Promoted}; +use rustc::mir::visit::{MutVisitor, TyContext}; use rustc::infer::{InferCtxt, NLLRegionVariableOrigin}; use rustc_index::vec::IndexVec; @@ -62,23 +62,15 @@ fn visit_ty(&mut self, ty: &mut Ty<'tcx>, ty_context: TyContext) { debug!("visit_ty: ty={:?}", ty); } - fn visit_place( + fn process_projection_elem( &mut self, - place: &mut Place<'tcx>, - context: PlaceContext, - location: Location, - ) { - self.visit_place_base(&mut place.base, context, location); - - let new_projection: Vec<_> = place.projection.iter().map(|elem| - if let PlaceElem::Field(field, ty) = elem { - PlaceElem::Field(*field, self.renumber_regions(ty)) - } else { - elem.clone() - } - ).collect(); - - place.projection = new_projection.into_boxed_slice(); + elem: &PlaceElem<'tcx>, + ) -> PlaceElem<'tcx> { + if let PlaceElem::Field(field, ty) = elem { + PlaceElem::Field(*field, self.renumber_regions(ty)) + } else { + elem.clone() + } } fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, location: Location) { diff --git a/src/librustc_mir/transform/erase_regions.rs b/src/librustc_mir/transform/erase_regions.rs index 132149d5d43..725a8de8fe7 100644 --- a/src/librustc_mir/transform/erase_regions.rs +++ b/src/librustc_mir/transform/erase_regions.rs @@ -7,7 +7,7 @@ use rustc::ty::subst::SubstsRef; use rustc::ty::{self, Ty, TyCtxt}; use rustc::mir::*; -use rustc::mir::visit::{MutVisitor, PlaceContext, TyContext}; +use rustc::mir::visit::{MutVisitor, TyContext}; use crate::transform::{MirPass, MirSource}; struct EraseRegionsVisitor<'tcx> { @@ -39,23 +39,15 @@ fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, _: Location) { *substs = self.tcx.erase_regions(substs); } - fn visit_place( + fn process_projection_elem( &mut self, - place: &mut Place<'tcx>, - context: PlaceContext, - location: Location, - ) { - self.visit_place_base(&mut place.base, context, location); - - let new_projection: Vec<_> = place.projection.iter().map(|elem| - if let PlaceElem::Field(field, ty) = elem { - PlaceElem::Field(*field, self.tcx.erase_regions(ty)) - } else { - elem.clone() - } - ).collect(); - - place.projection = new_projection.into_boxed_slice(); + elem: &PlaceElem<'tcx>, + ) -> PlaceElem<'tcx> { + if let PlaceElem::Field(field, ty) = elem { + PlaceElem::Field(*field, self.tcx.erase_regions(ty)) + } else { + elem.clone() + } } } diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 3a71d22da78..dd13d0c9655 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -695,21 +695,22 @@ fn visit_place( *place = self.destination.clone(); }, _ => { - self.visit_place_base(&mut place.base, context, location); - - let new_projection: Vec<_> = place.projection.iter().map(|elem| - if let PlaceElem::Index(local) = elem { - PlaceElem::Index(self.make_integrate_local(local)) - } else { - elem.clone() - } - ).collect(); - - place.projection = new_projection.into_boxed_slice(); + self.super_place(place, context, location); } } } + fn process_projection_elem( + &mut self, + elem: &PlaceElem<'tcx>, + ) -> PlaceElem<'tcx> { + if let PlaceElem::Index(local) = elem { + PlaceElem::Index(self.make_integrate_local(local)) + } else { + elem.clone() + } + } + 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); diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index d1c79c5ae2a..565f260546b 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -405,24 +405,16 @@ fn visit_local(&mut self, } } - fn visit_place( + fn process_projection_elem( &mut self, - place: &mut Place<'tcx>, - context: PlaceContext, - location: Location, - ) { - self.visit_place_base(&mut place.base, context, location); - - let new_projection: Vec<_> = place.projection.iter().map(|elem| - match elem { - PlaceElem::Index(local) if self.is_temp_kind(*local) => { - PlaceElem::Index(self.promote_temp(*local)) - } - _ => elem.clone(), + elem: &PlaceElem<'tcx>, + ) -> PlaceElem<'tcx> { + match elem { + PlaceElem::Index(local) if self.is_temp_kind(*local) => { + PlaceElem::Index(self.promote_temp(*local)) } - ).collect(); - - place.projection = new_projection.into_boxed_slice(); + _ => elem.clone(), + } } } diff --git a/src/librustc_mir/transform/simplify.rs b/src/librustc_mir/transform/simplify.rs index 57bc1c8fab9..7dca3e357cc 100644 --- a/src/librustc_mir/transform/simplify.rs +++ b/src/librustc_mir/transform/simplify.rs @@ -371,22 +371,14 @@ fn visit_local(&mut self, l: &mut Local, _: PlaceContext, _: Location) { *l = self.map[*l].unwrap(); } - fn visit_place( + fn process_projection_elem( &mut self, - place: &mut Place<'tcx>, - context: PlaceContext, - location: Location, - ) { - self.visit_place_base(&mut place.base, context, location); - - let new_projection: Vec<_> = place.projection.iter().map(|elem| - if let PlaceElem::Index(local) = elem { - PlaceElem::Index(self.map[*local].unwrap()) - } else { - elem.clone() - } - ).collect(); - - place.projection = new_projection.into_boxed_slice(); + elem: &PlaceElem<'tcx>, + ) -> PlaceElem<'tcx> { + if let PlaceElem::Index(local) = elem { + PlaceElem::Index(self.map[*local].unwrap()) + } else { + elem.clone() + } } } diff --git a/src/librustc_mir/util/def_use.rs b/src/librustc_mir/util/def_use.rs index 5b5f7d83f07..25930df020a 100644 --- a/src/librustc_mir/util/def_use.rs +++ b/src/librustc_mir/util/def_use.rs @@ -1,6 +1,6 @@ //! Def-use analysis. -use rustc::mir::{Body, Local, Location, Place, PlaceElem}; +use rustc::mir::{Body, Local, Location, PlaceElem}; use rustc::mir::visit::{PlaceContext, MutVisitor, Visitor}; use rustc_index::vec::IndexVec; use std::mem; @@ -138,21 +138,15 @@ fn visit_local(&mut self, } } - fn visit_place(&mut self, - place: &mut Place<'tcx>, - context: PlaceContext, - location: Location) { - self.visit_place_base(&mut place.base, context, location); - - let new_projection: Vec<_> = place.projection.iter().map(|elem| - match elem { - PlaceElem::Index(local) if *local == self.query => { - PlaceElem::Index(self.new_local) - } - _ => elem.clone(), + fn process_projection_elem( + &mut self, + elem: &PlaceElem<'tcx>, + ) -> PlaceElem<'tcx> { + match elem { + PlaceElem::Index(local) if *local == self.query => { + PlaceElem::Index(self.new_local) } - ).collect(); - - place.projection = new_projection.into_boxed_slice(); + _ => elem.clone(), + } } }