@@ -267,7 +267,8 @@ pub fn implement_drop_glue<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
267267
268268fn trans_struct_drop < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > ,
269269 t : Ty < ' tcx > ,
270- v0 : ValueRef )
270+ v0 : ValueRef ,
271+ shallow_drop : bool )
271272 -> Block < ' blk , ' tcx >
272273{
273274 debug ! ( "trans_struct_drop t: {}" , t) ;
@@ -286,7 +287,9 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
286287
287288 // Issue #23611: schedule cleanup of contents, re-inspecting the
288289 // discriminant (if any) in case of variant swap in drop code.
289- bcx. fcx . schedule_drop_adt_contents ( contents_scope, v0, t) ;
290+ if !shallow_drop {
291+ bcx. fcx . schedule_drop_adt_contents ( contents_scope, v0, t) ;
292+ }
290293
291294 let ( sized_args, unsized_args) ;
292295 let args: & [ ValueRef ] = if type_is_sized ( tcx, t) {
@@ -470,9 +473,6 @@ fn make_drop_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v0: ValueRef, g: DropGlueK
470473 trans_exchange_free_ty ( bcx, llbox, content_ty, DebugLoc :: None )
471474 }
472475 }
473- ty:: TyUnion ( ..) => {
474- unimplemented_unions ! ( ) ;
475- }
476476 ty:: TyTrait ( ..) => {
477477 // No support in vtable for distinguishing destroying with
478478 // versus without calling Drop::drop. Assert caller is
@@ -491,6 +491,13 @@ fn make_drop_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v0: ValueRef, g: DropGlueK
491491 if def. dtor_kind ( ) . is_present ( ) && !skip_dtor => {
492492 trans_struct_drop ( bcx, t, v0)
493493 }
494+ ty:: TyUnion ( def, _) => {
495+ if def. dtor_kind ( ) . is_present ( ) && !skip_dtor {
496+ trans_struct_drop ( bcx, t, v0, true )
497+ } else {
498+ bcx
499+ }
500+ }
494501 _ => {
495502 if bcx. fcx . type_needs_drop ( t) {
496503 drop_structural_ty ( bcx, v0, t)
0 commit comments