From f7d9b439720fed4434a532244f0eb873cf14eb91 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Thu, 23 Apr 2015 22:45:03 +0200 Subject: [PATCH] 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.) --- src/librustc_trans/trans/adt.rs | 1 + src/librustc_trans/trans/base.rs | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/librustc_trans/trans/adt.rs b/src/librustc_trans/trans/adt.rs index ffa068a2ae44..2057f502c1b6 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 59f3ff726026..f3d82970e4ee 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);