This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +9
-11
lines changed
compiler/rustc_middle/src/mir Expand file tree Collapse file tree 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> {
279279 tcx : TyCtxt < ' tcx > ,
280280 param_env : ty:: ParamEnv < ' tcx > ,
281281 ) -> 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+ }
283290 }
284291
285292 #[ inline]
@@ -288,16 +295,7 @@ impl<'tcx> Const<'tcx> {
288295 tcx : TyCtxt < ' tcx > ,
289296 param_env : ty:: ParamEnv < ' tcx > ,
290297 ) -> 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 ( )
301299 }
302300
303301 #[ inline]
You can’t perform that action at this time.
0 commit comments