Skip to content

Commit c3e71d8

Browse files
committed
Fix a variant index and variant discriminant confusion
Previously for enums using the `Variants::Single` layout, the variant index was being confused with its discriminant. For example, in the case of `enum E { A = 1 }`. Use `discriminant_for_variant` to avoid the issue.
1 parent d5a91f3 commit c3e71d8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

compiler/rustc_mir_transform/src/uninhabited_enum_branching.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ fn variant_discriminants<'tcx>(
5555
match &layout.variants {
5656
Variants::Single { index } => {
5757
let mut res = FxHashSet::default();
58-
res.insert(index.as_u32() as u128);
58+
res.insert(
59+
ty.discriminant_for_variant(tcx, *index)
60+
.map_or(index.as_u32() as u128, |discr| discr.val),
61+
);
5962
res
6063
}
6164
Variants::Multiple { variants, .. } => variants

0 commit comments

Comments
 (0)