@@ -362,31 +362,31 @@ impl<'a, 'tcx> MoveData<'tcx> {
362362
363363 /// Adds a new move entry for a move of `lp` that occurs at location `id` with kind `kind`.
364364 pub fn add_move ( & self , tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
365- lp : Rc < LoanPath < ' tcx > > ,
365+ orig_lp : Rc < LoanPath < ' tcx > > ,
366366 id : ast:: NodeId ,
367367 kind : MoveKind ) {
368- // Moving one union field automatically moves all its fields.
369- if let LpExtend ( ref base_lp, mutbl, LpInterior ( opt_variant_id, interior) ) = lp. kind {
370- if let ty:: TyAdt ( adt_def, _) = base_lp. ty . sty {
368+ // Moving one union field automatically moves all its fields. Also move siblings of
369+ // all parent union fields, moves do not propagate upwards automatically.
370+ let mut lp = orig_lp. clone ( ) ;
371+ while let LpExtend ( ref base_lp, mutbl, lp_elem) = lp. clone ( ) . kind {
372+ if let ( & ty:: TyAdt ( adt_def, _) , LpInterior ( opt_variant_id, interior) )
373+ = ( & base_lp. ty . sty , lp_elem) {
371374 if adt_def. is_union ( ) {
372375 for field in & adt_def. struct_variant ( ) . fields {
373376 let field = InteriorKind :: InteriorField ( mc:: NamedField ( field. name ) ) ;
374- let field_ty = if field == interior {
375- lp. ty
376- } else {
377- tcx. types . err // Doesn't matter
378- } ;
379- let sibling_lp_kind = LpExtend ( base_lp. clone ( ) , mutbl,
380- LpInterior ( opt_variant_id, field) ) ;
381- let sibling_lp = Rc :: new ( LoanPath :: new ( sibling_lp_kind, field_ty) ) ;
382- self . add_move_helper ( tcx, sibling_lp, id, kind) ;
377+ if field != interior {
378+ let sibling_lp_kind =
379+ LpExtend ( base_lp. clone ( ) , mutbl, LpInterior ( opt_variant_id, field) ) ;
380+ let sibling_lp = Rc :: new ( LoanPath :: new ( sibling_lp_kind, tcx. types . err ) ) ;
381+ self . add_move_helper ( tcx, sibling_lp, id, kind) ;
382+ }
383383 }
384- return ;
385384 }
386385 }
386+ lp = base_lp. clone ( ) ;
387387 }
388388
389- self . add_move_helper ( tcx, lp . clone ( ) , id, kind) ;
389+ self . add_move_helper ( tcx, orig_lp . clone ( ) , id, kind) ;
390390 }
391391
392392 fn add_move_helper ( & self , tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
0 commit comments