diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2015-04-23 22:45:03 +0200 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2015-04-24 09:38:55 +0200 |
| commit | f7d9b439720fed4434a532244f0eb873cf14eb91 (patch) | |
| tree | 603924eeb1ba90605ecf24e3d74e52048b576a0e | |
| parent | 5910dc0e8e396a4af7b948b83bab03f27b414a0e (diff) | |
| download | rust-f7d9b439720fed4434a532244f0eb873cf14eb91.tar.gz rust-f7d9b439720fed4434a532244f0eb873cf14eb91.zip | |
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.)
| -rw-r--r-- | src/librustc_trans/trans/adt.rs | 1 | ||||
| -rw-r--r-- | 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 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); |
