File tree 2 files changed +10
-1
lines changed
compiler/rustc_middle/src/ty
2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -2067,7 +2067,9 @@ impl<'tcx> TyS<'tcx> {
2067
2067
) -> Option < Discr < ' tcx > > {
2068
2068
match self . kind ( ) {
2069
2069
TyKind :: Adt ( adt, _) if adt. variants . is_empty ( ) => {
2070
- bug ! ( "discriminant_for_variant called on zero variant enum" ) ;
2070
+ // This can actually happen during CTFE, see
2071
+ // https://github.com/rust-lang/rust/issues/89765.
2072
+ None
2071
2073
}
2072
2074
TyKind :: Adt ( adt, _) if adt. is_enum ( ) => {
2073
2075
Some ( adt. discriminant_for_variant ( tcx, variant_index) )
Original file line number Diff line number Diff line change @@ -25,6 +25,13 @@ enum SingleVariant {
25
25
26
26
const TEST_V : Discriminant < SingleVariant > = discriminant ( & SingleVariant :: V ) ;
27
27
28
+ pub const TEST_VOID : ( ) = {
29
+ // This is UB, but CTFE does not check validity so it does not detect this.
30
+ // This is a regression test for https://github.com/rust-lang/rust/issues/89765.
31
+ unsafe { std:: mem:: discriminant ( & * ( & ( ) as * const ( ) as * const Void ) ) ; } ;
32
+ } ;
33
+
34
+
28
35
fn main ( ) {
29
36
assert_eq ! ( TEST_A , TEST_A_OTHER ) ;
30
37
assert_eq ! ( TEST_A , discriminant( black_box( & Test :: A ( 17 ) ) ) ) ;
You can’t perform that action at this time.
0 commit comments