@@ -15,6 +15,7 @@ use rustc_data_structures::bitvec::BitArray;
1515use rustc_data_structures:: graph:: dominators:: Dominators ;
1616use rustc_data_structures:: indexed_vec:: { Idx , IndexVec } ;
1717use rustc:: mir:: { self , Location , TerminatorKind } ;
18+ use rustc:: mir:: tcx:: PlaceTy ;
1819use rustc:: mir:: visit:: { Visitor , PlaceContext } ;
1920use rustc:: mir:: traversal;
2021use rustc:: ty;
@@ -162,8 +163,9 @@ impl Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'll, 'tcx> {
162163 location : Location ) {
163164 let cx = self . fx . cx ;
164165
165- if !place. elems . is_empty ( ) {
166- for ( i, elem) in place. elems . iter ( ) . cloned ( ) . enumerate ( ) . rev ( ) {
166+ if !place. has_no_projection ( ) {
167+ let mut base_ty = place. base . ty ( self . fx . mir ) ;
168+ for elem in place. elems . iter ( ) . cloned ( ) {
167169 debug ! ( "visit_place(place={:?}, context={:?})" , place, context) ;
168170
169171 // Allow uses of projections that are ZSTs or from scalar fields.
@@ -172,20 +174,15 @@ impl Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'll, 'tcx> {
172174 _ => false
173175 } ;
174176
175- let base = place. elem_base ( cx. tcx , i) ;
176177 if is_consume {
177- let base_ty = base. ty ( self . fx . mir , cx. tcx ) ;
178- let base_ty = self . fx . monomorphize ( & base_ty) ;
178+ base_ty = self . fx . monomorphize ( & base_ty) ;
179179
180- // ZSTs don't require any actual memory access.
181- let elem_ty = base_ty. projection_ty ( cx. tcx , & elem) . to_ty ( cx. tcx ) ;
182- let elem_ty = self . fx . monomorphize ( & elem_ty) ;
183- if cx. layout_of ( elem_ty) . is_zst ( ) {
180+ if cx. layout_of ( base_ty) . is_zst ( ) {
184181 return ;
185182 }
186183
187184 if let mir:: ProjectionElem :: Field ( ..) = elem {
188- let layout = cx. layout_of ( base_ty. to_ty ( cx . tcx ) ) ;
185+ let layout = cx. layout_of ( base_ty) ;
189186 if layout. is_llvm_immediate ( ) || layout. is_llvm_scalar_pair ( ) {
190187 // Recurse with the same context, instead of `Projection`,
191188 // potentially stopping at non-operand projections,
@@ -200,6 +197,7 @@ impl Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'll, 'tcx> {
200197 context = PlaceContext :: Copy ;
201198 continue ;
202199 }
200+ base_ty = PlaceTy :: from ( base_ty) . projection_ty ( cx. tcx , & elem) . to_ty ( cx. tcx ) ;
203201 }
204202 }
205203
0 commit comments