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.)
This commit is contained in:
Felix S. Klock II 2015-04-23 22:45:03 +02:00
parent 5910dc0e8e
commit f7d9b43972
2 changed files with 6 additions and 2 deletions

View File

@ -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)
}
}

View File

@ -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);