@@ -937,17 +937,17 @@ impl<'tcx> PatRange<'tcx> {
937937 // Also, for performance, it's important to only do the second `try_to_bits` if necessary.
938938 let lo_is_min = match self . lo {
939939 PatRangeBoundary :: NegInfinity => true ,
940- PatRangeBoundary :: Finite ( value) => {
941- let lo = value. try_to_bits ( size ) . unwrap ( ) ^ bias;
940+ PatRangeBoundary :: Finite ( _ty , value) => {
941+ let lo = value. unwrap_leaf ( ) . to_bits ( size ) ^ bias;
942942 lo <= min
943943 }
944944 PatRangeBoundary :: PosInfinity => false ,
945945 } ;
946946 if lo_is_min {
947947 let hi_is_max = match self . hi {
948948 PatRangeBoundary :: NegInfinity => false ,
949- PatRangeBoundary :: Finite ( value) => {
950- let hi = value. try_to_bits ( size ) . unwrap ( ) ^ bias;
949+ PatRangeBoundary :: Finite ( _ty , value) => {
950+ let hi = value. unwrap_leaf ( ) . to_bits ( size ) ^ bias;
951951 hi > max || hi == max && self . end == RangeEnd :: Included
952952 }
953953 PatRangeBoundary :: PosInfinity => true ,
@@ -960,22 +960,16 @@ impl<'tcx> PatRange<'tcx> {
960960 }
961961
962962 #[ inline]
963- pub fn contains (
964- & self ,
965- value : mir:: Const < ' tcx > ,
966- tcx : TyCtxt < ' tcx > ,
967- typing_env : ty:: TypingEnv < ' tcx > ,
968- ) -> Option < bool > {
963+ pub fn contains ( & self , value : ty:: ValTree < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Option < bool > {
969964 use Ordering :: * ;
970- debug_assert_eq ! ( self . ty, value. ty( ) ) ;
971965 let ty = self . ty ;
972- let value = PatRangeBoundary :: Finite ( value) ;
966+ let value = PatRangeBoundary :: Finite ( ty , value) ;
973967 // For performance, it's important to only do the second comparison if necessary.
974968 Some (
975- match self . lo . compare_with ( value, ty, tcx, typing_env ) ? {
969+ match self . lo . compare_with ( value, ty, tcx) ? {
976970 Less | Equal => true ,
977971 Greater => false ,
978- } && match value. compare_with ( self . hi , ty, tcx, typing_env ) ? {
972+ } && match value. compare_with ( self . hi , ty, tcx) ? {
979973 Less => true ,
980974 Equal => self . end == RangeEnd :: Included ,
981975 Greater => false ,
@@ -984,21 +978,16 @@ impl<'tcx> PatRange<'tcx> {
984978 }
985979
986980 #[ inline]
987- pub fn overlaps (
988- & self ,
989- other : & Self ,
990- tcx : TyCtxt < ' tcx > ,
991- typing_env : ty:: TypingEnv < ' tcx > ,
992- ) -> Option < bool > {
981+ pub fn overlaps ( & self , other : & Self , tcx : TyCtxt < ' tcx > ) -> Option < bool > {
993982 use Ordering :: * ;
994983 debug_assert_eq ! ( self . ty, other. ty) ;
995984 // For performance, it's important to only do the second comparison if necessary.
996985 Some (
997- match other. lo . compare_with ( self . hi , self . ty , tcx, typing_env ) ? {
986+ match other. lo . compare_with ( self . hi , self . ty , tcx) ? {
998987 Less => true ,
999988 Equal => self . end == RangeEnd :: Included ,
1000989 Greater => false ,
1001- } && match self . lo . compare_with ( other. hi , self . ty , tcx, typing_env ) ? {
990+ } && match self . lo . compare_with ( other. hi , self . ty , tcx) ? {
1002991 Less => true ,
1003992 Equal => other. end == RangeEnd :: Included ,
1004993 Greater => false ,
@@ -1009,10 +998,13 @@ impl<'tcx> PatRange<'tcx> {
1009998
1010999impl < ' tcx > fmt:: Display for PatRange < ' tcx > {
10111000 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1012- if let PatRangeBoundary :: Finite ( value) = & self . lo {
1001+ if let & PatRangeBoundary :: Finite ( ty, value) = & self . lo {
1002+ // `ty::Value` has a reasonable pretty-printing implementation.
1003+ let value = ty:: Value { ty, valtree : value } ;
10131004 write ! ( f, "{value}" ) ?;
10141005 }
1015- if let PatRangeBoundary :: Finite ( value) = & self . hi {
1006+ if let & PatRangeBoundary :: Finite ( ty, value) = & self . hi {
1007+ let value = ty:: Value { ty, valtree : value } ;
10161008 write ! ( f, "{}" , self . end) ?;
10171009 write ! ( f, "{value}" ) ?;
10181010 } else {
@@ -1027,7 +1019,7 @@ impl<'tcx> fmt::Display for PatRange<'tcx> {
10271019/// If present, the const must be of a numeric type.
10281020#[ derive( Copy , Clone , Debug , PartialEq , HashStable , TypeVisitable ) ]
10291021pub enum PatRangeBoundary < ' tcx > {
1030- Finite ( mir :: Const < ' tcx > ) ,
1022+ Finite ( Ty < ' tcx > , ty :: ValTree < ' tcx > ) ,
10311023 NegInfinity ,
10321024 PosInfinity ,
10331025}
@@ -1038,20 +1030,15 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10381030 matches ! ( self , Self :: Finite ( ..) )
10391031 }
10401032 #[ inline]
1041- pub fn as_finite ( self ) -> Option < mir :: Const < ' tcx > > {
1033+ pub fn as_finite ( self ) -> Option < ty :: ValTree < ' tcx > > {
10421034 match self {
1043- Self :: Finite ( value) => Some ( value) ,
1035+ Self :: Finite ( _ty , value) => Some ( value) ,
10441036 Self :: NegInfinity | Self :: PosInfinity => None ,
10451037 }
10461038 }
1047- pub fn eval_bits (
1048- self ,
1049- ty : Ty < ' tcx > ,
1050- tcx : TyCtxt < ' tcx > ,
1051- typing_env : ty:: TypingEnv < ' tcx > ,
1052- ) -> u128 {
1039+ pub fn eval_bits ( self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> u128 {
10531040 match self {
1054- Self :: Finite ( value) => value. eval_bits ( tcx , typing_env ) ,
1041+ Self :: Finite ( _ty , value) => value. unwrap_leaf ( ) . to_bits_unchecked ( ) ,
10551042 Self :: NegInfinity => {
10561043 // Unwrap is ok because the type is known to be numeric.
10571044 ty. numeric_min_and_max_as_bits ( tcx) . unwrap ( ) . 0
@@ -1063,14 +1050,8 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10631050 }
10641051 }
10651052
1066- #[ instrument( skip( tcx, typing_env) , level = "debug" , ret) ]
1067- pub fn compare_with (
1068- self ,
1069- other : Self ,
1070- ty : Ty < ' tcx > ,
1071- tcx : TyCtxt < ' tcx > ,
1072- typing_env : ty:: TypingEnv < ' tcx > ,
1073- ) -> Option < Ordering > {
1053+ #[ instrument( skip( tcx) , level = "debug" , ret) ]
1054+ pub fn compare_with ( self , other : Self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Option < Ordering > {
10741055 use PatRangeBoundary :: * ;
10751056 match ( self , other) {
10761057 // When comparing with infinities, we must remember that `0u8..` and `0u8..=255`
@@ -1084,7 +1065,9 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10841065 // we can do scalar comparisons. E.g. `unicode-normalization` has
10851066 // many ranges such as '\u{037A}'..='\u{037F}', and chars can be compared
10861067 // in this way.
1087- ( Finite ( a) , Finite ( b) ) if matches ! ( ty. kind( ) , ty:: Int ( _) | ty:: Uint ( _) | ty:: Char ) => {
1068+ ( Finite ( _, a) , Finite ( _, b) )
1069+ if matches ! ( ty. kind( ) , ty:: Int ( _) | ty:: Uint ( _) | ty:: Char ) =>
1070+ {
10881071 if let ( Some ( a) , Some ( b) ) = ( a. try_to_scalar_int ( ) , b. try_to_scalar_int ( ) ) {
10891072 let sz = ty. primitive_size ( tcx) ;
10901073 let cmp = match ty. kind ( ) {
@@ -1098,8 +1081,8 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10981081 _ => { }
10991082 }
11001083
1101- let a = self . eval_bits ( ty, tcx, typing_env ) ;
1102- let b = other. eval_bits ( ty, tcx, typing_env ) ;
1084+ let a = self . eval_bits ( ty, tcx) ;
1085+ let b = other. eval_bits ( ty, tcx) ;
11031086
11041087 match ty. kind ( ) {
11051088 ty:: Float ( ty:: FloatTy :: F16 ) => {
0 commit comments