@@ -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 ;
@@ -761,8 +763,37 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
761763 span_bug ! ( span, "break value must be a scope" )
762764 } ;
763765
764- // FIXME accept bare MyEnum::Foo as constant
765- let constant = self . as_constant ( & self . thir [ value] ) ;
766+ let constant = match & self . thir [ value] . kind {
767+ ExprKind :: Adt ( box AdtExpr { variant_index, fields, base, .. } ) => {
768+ assert ! ( matches!( base, AdtExprBase :: None ) ) ;
769+ assert ! ( fields. is_empty( ) ) ;
770+ ConstOperand {
771+ span : self . thir [ value] . span ,
772+ user_ty : None ,
773+ const_ : Const :: Ty (
774+ self . thir [ value] . ty ,
775+ ty:: Const :: new (
776+ self . tcx ,
777+ ty:: ConstKind :: Value ( ty:: Value {
778+ ty : self . thir [ value] . ty ,
779+ valtree : ValTree :: from_branches (
780+ self . tcx ,
781+ Some ( ValTree :: from_scalar_int (
782+ self . tcx ,
783+ ty:: ScalarInt :: try_from_uint (
784+ variant_index. as_u32 ( ) ,
785+ Size :: from_bits ( 32 ) ,
786+ )
787+ . unwrap ( ) ,
788+ ) ) ,
789+ ) ,
790+ } ) ,
791+ ) ,
792+ ) ,
793+ }
794+ }
795+ _ => self . as_constant ( & self . thir [ value] ) ,
796+ } ;
766797
767798 let break_index = self
768799 . scopes
0 commit comments