@@ -88,8 +88,9 @@ use rustc_hir::HirId;
88
88
use rustc_index:: { IndexSlice , IndexVec } ;
89
89
use rustc_middle:: middle:: region;
90
90
use rustc_middle:: mir:: * ;
91
- use rustc_middle:: thir:: { ArmId , ExprId , LintLevel } ;
92
- use rustc_middle:: { bug, span_bug} ;
91
+ use rustc_middle:: thir:: { AdtExpr , AdtExprBase , ArmId , ExprId , ExprKind , LintLevel } ;
92
+ use rustc_middle:: ty:: ValTree ;
93
+ use rustc_middle:: { bug, span_bug, ty} ;
93
94
use rustc_pattern_analysis:: rustc:: RustcPatCtxt ;
94
95
use rustc_session:: lint:: Level ;
95
96
use rustc_span:: source_map:: Spanned ;
@@ -824,8 +825,28 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
824
825
span_bug ! ( span, "break value must be a scope" )
825
826
} ;
826
827
827
- // FIXME accept bare MyEnum::Foo as constant
828
- let constant = self . as_constant ( & self . thir [ value] ) ;
828
+ let constant = match & self . thir [ value] . kind {
829
+ ExprKind :: Adt ( box AdtExpr { variant_index, fields, base, .. } ) => {
830
+ assert ! ( matches!( base, AdtExprBase :: None ) ) ;
831
+ assert ! ( fields. is_empty( ) ) ;
832
+ ConstOperand {
833
+ span : self . thir [ value] . span ,
834
+ user_ty : None ,
835
+ const_ : Const :: Ty (
836
+ self . thir [ value] . ty ,
837
+ ty:: Const :: new_value (
838
+ self . tcx ,
839
+ ValTree :: from_branches (
840
+ self . tcx ,
841
+ [ ValTree :: from_scalar_int ( self . tcx , variant_index. as_u32 ( ) . into ( ) ) ] ,
842
+ ) ,
843
+ self . thir [ value] . ty ,
844
+ ) ,
845
+ ) ,
846
+ }
847
+ }
848
+ _ => self . as_constant ( & self . thir [ value] ) ,
849
+ } ;
829
850
830
851
let break_index = self
831
852
. scopes
0 commit comments