@@ -20,7 +20,7 @@ use llvm::{ValueRef, get_param};
20
20
use middle:: lang_items:: BoxFreeFnLangItem ;
21
21
use rustc:: ty:: subst:: { Substs } ;
22
22
use rustc:: traits;
23
- use rustc:: ty:: { self , AdtDef , AdtKind , Ty , TypeFoldable } ;
23
+ use rustc:: ty:: { self , layout , AdtDef , AdtKind , Ty , TypeFoldable } ;
24
24
use rustc:: ty:: subst:: Kind ;
25
25
use rustc:: mir:: tcx:: LvalueTy ;
26
26
use mir:: lvalue:: LvalueRef ;
@@ -471,14 +471,22 @@ fn drop_structural_ty<'a, 'tcx>(cx: Builder<'a, 'tcx>, ptr: LvalueRef<'tcx>) ->
471
471
// NB: we must hit the discriminant first so that structural
472
472
// comparison know not to proceed when the discriminants differ.
473
473
474
- match adt:: trans_switch ( & cx, t, ptr. llval , false ) {
475
- ( adt:: BranchKind :: Single , None ) => {
474
+ // Obtain a representation of the discriminant sufficient to translate
475
+ // destructuring; this may or may not involve the actual discriminant.
476
+ let l = cx. ccx . layout_of ( t) ;
477
+ match * l {
478
+ layout:: Univariant { .. } |
479
+ layout:: UntaggedUnion { .. } => {
476
480
if n_variants != 0 {
477
481
assert ! ( n_variants == 1 ) ;
478
482
iter_variant ( & cx, ptr, & adt, 0 , substs) ;
479
483
}
480
484
}
481
- ( adt:: BranchKind :: Switch , Some ( lldiscrim_a) ) => {
485
+ layout:: CEnum { .. } |
486
+ layout:: General { .. } |
487
+ layout:: RawNullablePointer { .. } |
488
+ layout:: StructWrappedNullablePointer { .. } => {
489
+ let lldiscrim_a = adt:: trans_get_discr ( & cx, t, ptr. llval , None , false ) ;
482
490
let tcx = cx. tcx ( ) ;
483
491
drop_ty ( & cx, LvalueRef :: new_sized_ty ( lldiscrim_a, tcx. types . isize ) ) ;
484
492
@@ -511,7 +519,7 @@ fn drop_structural_ty<'a, 'tcx>(cx: Builder<'a, 'tcx>, ptr: LvalueRef<'tcx>) ->
511
519
}
512
520
cx = next_cx;
513
521
}
514
- _ => cx . sess ( ) . unimpl ( "value from adt::trans_switch in drop_structural_ty" ) ,
522
+ _ => bug ! ( "{} is not an enum." , t ) ,
515
523
}
516
524
}
517
525
} ,
0 commit comments