@@ -88,8 +88,8 @@ use rustc_hir::HirId;
8888use rustc_index:: { IndexSlice , IndexVec } ;
8989use rustc_middle:: middle:: region;
9090use rustc_middle:: mir:: * ;
91- use rustc_middle:: thir:: { ArmId , ExprId , LintLevel } ;
92- use rustc_middle:: ty:: { self , TyCtxt } ;
91+ use rustc_middle:: thir:: { AdtExpr , AdtExprBase , ArmId , ExprId , ExprKind , LintLevel } ;
92+ use rustc_middle:: ty:: { self , TyCtxt , ValTree } ;
9393use rustc_middle:: { bug, span_bug} ;
9494use rustc_pattern_analysis:: rustc:: RustcPatCtxt ;
9595use rustc_session:: lint:: Level ;
@@ -830,8 +830,28 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
830830 span_bug ! ( span, "break value must be a scope" )
831831 } ;
832832
833- // FIXME accept bare MyEnum::Foo as constant
834- let constant = self . as_constant ( & self . thir [ value] ) ;
833+ let constant = match & self . thir [ value] . kind {
834+ ExprKind :: Adt ( box AdtExpr { variant_index, fields, base, .. } ) => {
835+ assert ! ( matches!( base, AdtExprBase :: None ) ) ;
836+ assert ! ( fields. is_empty( ) ) ;
837+ ConstOperand {
838+ span : self . thir [ value] . span ,
839+ user_ty : None ,
840+ const_ : Const :: Ty (
841+ self . thir [ value] . ty ,
842+ ty:: Const :: new_value (
843+ self . tcx ,
844+ ValTree :: from_branches (
845+ self . tcx ,
846+ [ ValTree :: from_scalar_int ( self . tcx , variant_index. as_u32 ( ) . into ( ) ) ] ,
847+ ) ,
848+ self . thir [ value] . ty ,
849+ ) ,
850+ ) ,
851+ }
852+ }
853+ _ => self . as_constant ( & self . thir [ value] ) ,
854+ } ;
835855
836856 let break_index = self
837857 . scopes
0 commit comments