This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +9
-8
lines changed
compiler/rustc_middle/src Expand file tree Collapse file tree 2 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -297,7 +297,15 @@ impl<'tcx> Const<'tcx> {
297
297
tcx : TyCtxt < ' tcx > ,
298
298
param_env : ty:: ParamEnv < ' tcx > ,
299
299
) -> Option < ScalarInt > {
300
- self . try_eval_scalar ( tcx, param_env) ?. try_to_int ( ) . ok ( )
300
+ match self {
301
+ // Fast path for already evaluated constants.
302
+ Const :: Val ( ConstValue :: Scalar ( Scalar :: Int ( scalar_int) ) , _) => Some ( scalar_int) ,
303
+ Const :: Ty ( c)
304
+ if let ty:: ConstKind :: Value ( ty:: ValTree :: Leaf ( scalar_int) ) = c. kind ( )
305
+ && c. ty ( ) . is_primitive ( )
306
+ => Some ( scalar_int) ,
307
+ _ => self . try_eval_scalar ( tcx, param_env) ?. try_to_int ( ) . ok ( ) ,
308
+ }
301
309
}
302
310
303
311
#[ inline]
Original file line number Diff line number Diff line change @@ -941,13 +941,6 @@ impl<'tcx> PatRangeBoundary<'tcx> {
941
941
param_env : ty:: ParamEnv < ' tcx > ,
942
942
) -> u128 {
943
943
match self {
944
- Self :: Finite {
945
- value : mir:: Const :: Val ( mir:: ConstValue :: Scalar ( Scalar :: Int ( scalar_int) ) , _) ,
946
- } => scalar_int. assert_bits ( scalar_int. size ( ) ) ,
947
- Self :: Finite {
948
- value : mir:: Const :: Ty ( c) ,
949
- } if let ty:: ConstKind :: Value ( ty:: ValTree :: Leaf ( scalar_int) ) = c. kind ( )
950
- => scalar_int. assert_bits ( scalar_int. size ( ) ) ,
951
944
Self :: Finite { value } => value. eval_bits ( tcx, param_env) ,
952
945
// Self::NegInfinity => {
953
946
// // Unwrap is ok because the type is known to be numeric.
You can’t perform that action at this time.
0 commit comments