Skip to content

Commit f7d9b43

Browse files
committed
Latent bug in iter_structural_ty: handle _match::Single on zero-variant enum.
(This may not be the *best* fix, compared to e.g. returning `_match::NoBranch` from `trans_switch` on a zero-variant enum. But it is one of the *simplest* fixes available.)
1 parent 5910dc0 commit f7d9b43

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/librustc_trans/trans/adt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ pub fn trans_switch<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
769769
(_match::Switch, Some(trans_get_discr(bcx, r, scrutinee, None)))
770770
}
771771
Univariant(..) => {
772+
// N.B.: Univariant means <= 1 enum variants (*not* == 1 variants).
772773
(_match::Single, None)
773774
}
774775
}

src/librustc_trans/trans/base.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,11 @@ pub fn iter_structural_ty<'blk, 'tcx, F>(cx: Block<'blk, 'tcx>,
471471

472472
match adt::trans_switch(cx, &*repr, av) {
473473
(_match::Single, None) => {
474-
cx = iter_variant(cx, &*repr, av, &*(*variants)[0],
475-
substs, &mut f);
474+
if n_variants != 0 {
475+
assert!(n_variants == 1);
476+
cx = iter_variant(cx, &*repr, av, &*(*variants)[0],
477+
substs, &mut f);
478+
}
476479
}
477480
(_match::Switch, Some(lldiscrim_a)) => {
478481
cx = f(cx, lldiscrim_a, cx.tcx().types.isize);

0 commit comments

Comments
 (0)