File tree 1 file changed +9
-11
lines changed
compiler/rustc_middle/src/mir
1 file changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -279,7 +279,14 @@ impl<'tcx> Const<'tcx> {
279
279
tcx : TyCtxt < ' tcx > ,
280
280
param_env : ty:: ParamEnv < ' tcx > ,
281
281
) -> Option < Scalar > {
282
- self . eval ( tcx, param_env, None ) . ok ( ) ?. try_to_scalar ( )
282
+ match self {
283
+ Const :: Ty ( c) => {
284
+ // Avoid the `valtree_to_const_val` query.
285
+ let val = c. eval ( tcx, param_env, None ) . ok ( ) ?;
286
+ val. try_to_scalar ( )
287
+ }
288
+ _ => self . eval ( tcx, param_env, None ) . ok ( ) ?. try_to_scalar ( ) ,
289
+ }
283
290
}
284
291
285
292
#[ inline]
@@ -288,16 +295,7 @@ impl<'tcx> Const<'tcx> {
288
295
tcx : TyCtxt < ' tcx > ,
289
296
param_env : ty:: ParamEnv < ' tcx > ,
290
297
) -> Option < ScalarInt > {
291
- match self {
292
- // If the constant is already evaluated, we shortcut here.
293
- Const :: Ty ( c) if let ty:: ConstKind :: Value ( valtree) = c. kind ( ) => {
294
- valtree. try_to_scalar_int ( )
295
- } ,
296
- // This is a more general form of the previous case.
297
- _ => {
298
- self . try_eval_scalar ( tcx, param_env) ?. try_to_int ( ) . ok ( )
299
- } ,
300
- }
298
+ self . try_eval_scalar ( tcx, param_env) ?. try_to_int ( ) . ok ( )
301
299
}
302
300
303
301
#[ inline]
You can’t perform that action at this time.
0 commit comments