@@ -83,13 +83,15 @@ that contains only loops and breakable blocks. It tracks where a `break`,
8383
8484use std:: mem;
8585
86+ use rustc_abi:: Size ;
8687use rustc_data_structures:: fx:: FxHashMap ;
8788use rustc_hir:: HirId ;
8889use rustc_index:: { IndexSlice , IndexVec } ;
8990use rustc_middle:: middle:: region;
9091use rustc_middle:: mir:: * ;
91- use rustc_middle:: thir:: { ArmId , ExprId , LintLevel } ;
92- use rustc_middle:: { bug, span_bug} ;
92+ use rustc_middle:: thir:: { AdtExpr , AdtExprBase , ArmId , ExprId , ExprKind , LintLevel } ;
93+ use rustc_middle:: ty:: ValTree ;
94+ use rustc_middle:: { bug, span_bug, ty} ;
9395use rustc_pattern_analysis:: rustc:: RustcPatCtxt ;
9496use rustc_session:: lint:: Level ;
9597use rustc_span:: source_map:: Spanned ;
@@ -824,8 +826,37 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
824826 span_bug ! ( span, "break value must be a scope" )
825827 } ;
826828
827- // FIXME accept bare MyEnum::Foo as constant
828- let constant = self . as_constant ( & self . thir [ value] ) ;
829+ let constant = match & self . thir [ value] . kind {
830+ ExprKind :: Adt ( box AdtExpr { variant_index, fields, base, .. } ) => {
831+ assert ! ( matches!( base, AdtExprBase :: None ) ) ;
832+ assert ! ( fields. is_empty( ) ) ;
833+ ConstOperand {
834+ span : self . thir [ value] . span ,
835+ user_ty : None ,
836+ const_ : Const :: Ty (
837+ self . thir [ value] . ty ,
838+ ty:: Const :: new (
839+ self . tcx ,
840+ ty:: ConstKind :: Value ( ty:: Value {
841+ ty : self . thir [ value] . ty ,
842+ valtree : ValTree :: from_branches (
843+ self . tcx ,
844+ Some ( ValTree :: from_scalar_int (
845+ self . tcx ,
846+ ty:: ScalarInt :: try_from_uint (
847+ variant_index. as_u32 ( ) ,
848+ Size :: from_bits ( 32 ) ,
849+ )
850+ . unwrap ( ) ,
851+ ) ) ,
852+ ) ,
853+ } ) ,
854+ ) ,
855+ ) ,
856+ }
857+ }
858+ _ => self . as_constant ( & self . thir [ value] ) ,
859+ } ;
829860
830861 let break_index = self
831862 . scopes
0 commit comments