@@ -77,31 +77,9 @@ pub(crate) fn eval_mir_constant<'tcx>(
7777 fx : & FunctionCx < ' _ , ' _ , ' tcx > ,
7878 constant : & Constant < ' tcx > ,
7979) -> Option < ( ConstValue < ' tcx > , Ty < ' tcx > ) > {
80- let constant_kind = fx. monomorphize ( constant. literal ) ;
81- let uv = match constant_kind {
82- ConstantKind :: Ty ( const_) => match const_. kind ( ) {
83- ty:: ConstKind :: Unevaluated ( uv) => uv. expand ( ) ,
84- ty:: ConstKind :: Value ( val) => {
85- return Some ( ( fx. tcx . valtree_to_const_val ( ( const_. ty ( ) , val) ) , const_. ty ( ) ) ) ;
86- }
87- err => span_bug ! (
88- constant. span,
89- "encountered bad ConstKind after monomorphizing: {:?}" ,
90- err
91- ) ,
92- } ,
93- ConstantKind :: Unevaluated ( mir:: UnevaluatedConst { def, .. } , _)
94- if fx. tcx . is_static ( def) =>
95- {
96- span_bug ! ( constant. span, "MIR constant refers to static" ) ;
97- }
98- ConstantKind :: Unevaluated ( uv, _) => uv,
99- ConstantKind :: Val ( val, _) => return Some ( ( val, constant_kind. ty ( ) ) ) ,
100- } ;
101-
102- let val = fx
103- . tcx
104- . const_eval_resolve ( ty:: ParamEnv :: reveal_all ( ) , uv, None )
80+ let cv = fx. monomorphize ( constant. literal ) ;
81+ let val = cv
82+ . eval ( fx. tcx , ty:: ParamEnv :: reveal_all ( ) , Some ( constant. span ) )
10583 . map_err ( |err| match err {
10684 ErrorHandled :: Reported ( _) => {
10785 fx. tcx . sess . span_err ( constant. span , "erroneous constant encountered" ) ;
@@ -111,7 +89,7 @@ pub(crate) fn eval_mir_constant<'tcx>(
11189 }
11290 } )
11391 . ok ( ) ;
114- val. map ( |val| ( val, constant_kind . ty ( ) ) )
92+ val. map ( |val| ( val, cv . ty ( ) ) )
11593}
11694
11795pub ( crate ) fn codegen_constant_operand < ' tcx > (
0 commit comments