diff --git a/src/librustc_trans/trans/adt.rs b/src/librustc_trans/trans/adt.rs index ffa068a2ae4..2057f502c1b 100644 --- a/src/librustc_trans/trans/adt.rs +++ b/src/librustc_trans/trans/adt.rs @@ -769,6 +769,7 @@ pub fn trans_switch<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, (_match::Switch, Some(trans_get_discr(bcx, r, scrutinee, None))) } Univariant(..) => { + // N.B.: Univariant means <= 1 enum variants (*not* == 1 variants). (_match::Single, None) } } diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index 59f3ff72602..f3d82970e4e 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -471,8 +471,11 @@ pub fn iter_structural_ty<'blk, 'tcx, F>(cx: Block<'blk, 'tcx>, match adt::trans_switch(cx, &*repr, av) { (_match::Single, None) => { - cx = iter_variant(cx, &*repr, av, &*(*variants)[0], - substs, &mut f); + if n_variants != 0 { + assert!(n_variants == 1); + cx = iter_variant(cx, &*repr, av, &*(*variants)[0], + substs, &mut f); + } } (_match::Switch, Some(lldiscrim_a)) => { cx = f(cx, lldiscrim_a, cx.tcx().types.isize);