File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed
compiler/rustc_middle/src/ty Expand file tree Collapse file tree 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> {
20672067 ) -> Option < Discr < ' tcx > > {
20682068 match self . kind ( ) {
20692069 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
20712073 }
20722074 TyKind :: Adt ( adt, _) if adt. is_enum ( ) => {
20732075 Some ( adt. discriminant_for_variant ( tcx, variant_index) )
Original file line number Diff line number Diff line change @@ -25,6 +25,13 @@ enum SingleVariant {
2525
2626const TEST_V : Discriminant < SingleVariant > = discriminant ( & SingleVariant :: V ) ;
2727
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+
2835fn main ( ) {
2936 assert_eq ! ( TEST_A , TEST_A_OTHER ) ;
3037 assert_eq ! ( TEST_A , discriminant( black_box( & Test :: A ( 17 ) ) ) ) ;
You can’t perform that action at this time.
0 commit comments