Skip to content

Commit 422efd7

Browse files
committed
Use the actual discriminant instead of always choosing the dataful variant
1 parent 6b3202a commit 422efd7

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/librustc_mir/hair/pattern/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,10 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
878878
);
879879
})
880880
}
881-
ty::layout::Variants::NicheFilling { dataful_variant, .. } =>
882-
dataful_variant,
881+
ty::layout::Variants::NicheFilling { .. } => {
882+
assert_eq!(discr_val as usize as u128, discr_val);
883+
discr_val as usize
884+
},
883885
};
884886
let subpatterns = adt_subpatterns(
885887
adt_def.variants[variant_index].fields.len(),

src/test/run-pass/match-arm-statics.rs

+7
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ fn issue_14576() {
9494
const F : C = C::D;
9595

9696
assert_eq!(match C::D { F => 1, _ => 2, }, 1);
97+
98+
// test gaps
99+
#[derive(PartialEq, Eq)]
100+
enum G { H = 3, I = 5 }
101+
const K : G = G::I;
102+
103+
assert_eq!(match G::I { K => 1, _ => 2, }, 1);
97104
}
98105

99106
fn issue_13731() {

0 commit comments

Comments
 (0)