@@ -77,31 +77,9 @@ pub(crate) fn eval_mir_constant<'tcx>(
77
77
fx : & FunctionCx < ' _ , ' _ , ' tcx > ,
78
78
constant : & Constant < ' tcx > ,
79
79
) -> 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 ) )
105
83
. map_err ( |err| match err {
106
84
ErrorHandled :: Reported ( _) => {
107
85
fx. tcx . sess . span_err ( constant. span , "erroneous constant encountered" ) ;
@@ -111,7 +89,7 @@ pub(crate) fn eval_mir_constant<'tcx>(
111
89
}
112
90
} )
113
91
. ok ( ) ;
114
- val. map ( |val| ( val, constant_kind . ty ( ) ) )
92
+ val. map ( |val| ( val, cv . ty ( ) ) )
115
93
}
116
94
117
95
pub ( crate ) fn codegen_constant_operand < ' tcx > (
0 commit comments