@@ -16,7 +16,7 @@ use rustc_hir::{BindingAnnotation, ByRef, HirId, MatchSource, RangeEnd};
16
16
use rustc_index:: newtype_index;
17
17
use rustc_index:: IndexVec ;
18
18
use rustc_middle:: middle:: region;
19
- use rustc_middle:: mir:: interpret:: AllocId ;
19
+ use rustc_middle:: mir:: interpret:: { AllocId , Scalar } ;
20
20
use rustc_middle:: mir:: { self , BinOp , BorrowKind , FakeReadCause , UnOp } ;
21
21
use rustc_middle:: ty:: adjustment:: PointerCoercion ;
22
22
use rustc_middle:: ty:: layout:: IntegerExt ;
@@ -1009,11 +1009,16 @@ impl<'tcx> PatRangeBoundary<'tcx> {
1009
1009
1010
1010
// This code is hot when compiling matches with many ranges. So we
1011
1011
// special-case extraction of evaluated scalars for speed, for types where
1012
- // raw data comparisons are appropriate. E.g. `unicode-normalization` has
1012
+ // unsigned int comparisons are appropriate. E.g. `unicode-normalization` has
1013
1013
// many ranges such as '\u{037A}'..='\u{037F}', and chars can be compared
1014
1014
// in this way.
1015
1015
( Finite ( a) , Finite ( b) ) if matches ! ( ty. kind( ) , ty:: Uint ( _) | ty:: Char ) => {
1016
- if let ( Some ( a) , Some ( b) ) = ( a. try_to_scalar_int ( ) , b. try_to_scalar_int ( ) ) {
1016
+ let to_scalar_int = |x| match x {
1017
+ mir:: Const :: Val ( mir:: ConstValue :: Scalar ( Scalar :: Int ( x) ) , _) => Some ( x) ,
1018
+ mir:: Const :: Ty ( x) => Some ( x. to_valtree ( ) . unwrap_leaf ( ) ) ,
1019
+ _ => None ,
1020
+ } ;
1021
+ if let ( Some ( a) , Some ( b) ) = ( to_scalar_int ( a) , to_scalar_int ( b) ) {
1017
1022
let sz = ty. primitive_size ( tcx) ;
1018
1023
let a = a. assert_uint ( sz) ;
1019
1024
let b = b. assert_uint ( sz) ;
0 commit comments