@@ -320,8 +320,6 @@ fn base_local_and_movability<'tcx>(
320320 mir : & mir:: Body < ' tcx > ,
321321 place : mir:: Place < ' tcx > ,
322322) -> ( mir:: Local , CannotMoveOut ) {
323- use rustc_middle:: mir:: PlaceRef ;
324-
325323 // Dereference. You cannot move things out from a borrowed value.
326324 let mut deref = false ;
327325 // Accessing a field of an ADT that has `Drop`. Moving the field out will cause E0509.
@@ -330,17 +328,14 @@ fn base_local_and_movability<'tcx>(
330328 // underlying type implements Copy
331329 let mut slice = false ;
332330
333- let PlaceRef { local, mut projection } = place. as_ref ( ) ;
334- while let [ base @ .., elem] = projection {
335- projection = base;
331+ for ( base, elem) in place. as_ref ( ) . iter_projections ( ) {
332+ let base_ty = base. ty ( & mir. local_decls , cx. tcx ) . ty ;
336333 deref |= matches ! ( elem, mir:: ProjectionElem :: Deref ) ;
337- field |= matches ! ( elem, mir:: ProjectionElem :: Field ( ..) )
338- && has_drop ( cx, mir:: Place :: ty_from ( local, projection, & mir. local_decls , cx. tcx ) . ty ) ;
339- slice |= matches ! ( elem, mir:: ProjectionElem :: Index ( ..) )
340- && !is_copy ( cx, mir:: Place :: ty_from ( local, projection, & mir. local_decls , cx. tcx ) . ty ) ;
334+ field |= matches ! ( elem, mir:: ProjectionElem :: Field ( ..) ) && has_drop ( cx, base_ty) ;
335+ slice |= matches ! ( elem, mir:: ProjectionElem :: Index ( ..) ) && !is_copy ( cx, base_ty) ;
341336 }
342337
343- ( local, deref || field || slice)
338+ ( place . local , deref || field || slice)
344339}
345340
346341#[ derive( Default ) ]
0 commit comments