@@ -935,17 +935,17 @@ impl<'tcx> PatRange<'tcx> {
935935 // Also, for performance, it's important to only do the second `try_to_bits` if necessary.
936936 let lo_is_min = match self . lo {
937937 PatRangeBoundary :: NegInfinity => true ,
938- PatRangeBoundary :: Finite ( value) => {
939- let lo = value. try_to_bits ( size ) . unwrap ( ) ^ bias;
938+ PatRangeBoundary :: Finite ( _ty , value) => {
939+ let lo = value. unwrap_leaf ( ) . to_bits ( size ) ^ bias;
940940 lo <= min
941941 }
942942 PatRangeBoundary :: PosInfinity => false ,
943943 } ;
944944 if lo_is_min {
945945 let hi_is_max = match self . hi {
946946 PatRangeBoundary :: NegInfinity => false ,
947- PatRangeBoundary :: Finite ( value) => {
948- let hi = value. try_to_bits ( size ) . unwrap ( ) ^ bias;
947+ PatRangeBoundary :: Finite ( _ty , value) => {
948+ let hi = value. unwrap_leaf ( ) . to_bits ( size ) ^ bias;
949949 hi > max || hi == max && self . end == RangeEnd :: Included
950950 }
951951 PatRangeBoundary :: PosInfinity => true ,
@@ -958,22 +958,16 @@ impl<'tcx> PatRange<'tcx> {
958958 }
959959
960960 #[ inline]
961- pub fn contains (
962- & self ,
963- value : mir:: Const < ' tcx > ,
964- tcx : TyCtxt < ' tcx > ,
965- typing_env : ty:: TypingEnv < ' tcx > ,
966- ) -> Option < bool > {
961+ pub fn contains ( & self , value : ty:: ValTree < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Option < bool > {
967962 use Ordering :: * ;
968- debug_assert_eq ! ( self . ty, value. ty( ) ) ;
969963 let ty = self . ty ;
970- let value = PatRangeBoundary :: Finite ( value) ;
964+ let value = PatRangeBoundary :: Finite ( ty , value) ;
971965 // For performance, it's important to only do the second comparison if necessary.
972966 Some (
973- match self . lo . compare_with ( value, ty, tcx, typing_env ) ? {
967+ match self . lo . compare_with ( value, ty, tcx) ? {
974968 Less | Equal => true ,
975969 Greater => false ,
976- } && match value. compare_with ( self . hi , ty, tcx, typing_env ) ? {
970+ } && match value. compare_with ( self . hi , ty, tcx) ? {
977971 Less => true ,
978972 Equal => self . end == RangeEnd :: Included ,
979973 Greater => false ,
@@ -982,21 +976,16 @@ impl<'tcx> PatRange<'tcx> {
982976 }
983977
984978 #[ inline]
985- pub fn overlaps (
986- & self ,
987- other : & Self ,
988- tcx : TyCtxt < ' tcx > ,
989- typing_env : ty:: TypingEnv < ' tcx > ,
990- ) -> Option < bool > {
979+ pub fn overlaps ( & self , other : & Self , tcx : TyCtxt < ' tcx > ) -> Option < bool > {
991980 use Ordering :: * ;
992981 debug_assert_eq ! ( self . ty, other. ty) ;
993982 // For performance, it's important to only do the second comparison if necessary.
994983 Some (
995- match other. lo . compare_with ( self . hi , self . ty , tcx, typing_env ) ? {
984+ match other. lo . compare_with ( self . hi , self . ty , tcx) ? {
996985 Less => true ,
997986 Equal => self . end == RangeEnd :: Included ,
998987 Greater => false ,
999- } && match self . lo . compare_with ( other. hi , self . ty , tcx, typing_env ) ? {
988+ } && match self . lo . compare_with ( other. hi , self . ty , tcx) ? {
1000989 Less => true ,
1001990 Equal => other. end == RangeEnd :: Included ,
1002991 Greater => false ,
@@ -1007,10 +996,13 @@ impl<'tcx> PatRange<'tcx> {
1007996
1008997impl < ' tcx > fmt:: Display for PatRange < ' tcx > {
1009998 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1010- if let PatRangeBoundary :: Finite ( value) = & self . lo {
999+ if let & PatRangeBoundary :: Finite ( ty, value) = & self . lo {
1000+ // `ty::Value` has a reasonable pretty-printing implementation.
1001+ let value = ty:: Value { ty, valtree : value } ;
10111002 write ! ( f, "{value}" ) ?;
10121003 }
1013- if let PatRangeBoundary :: Finite ( value) = & self . hi {
1004+ if let & PatRangeBoundary :: Finite ( ty, value) = & self . hi {
1005+ let value = ty:: Value { ty, valtree : value } ;
10141006 write ! ( f, "{}" , self . end) ?;
10151007 write ! ( f, "{value}" ) ?;
10161008 } else {
@@ -1025,7 +1017,7 @@ impl<'tcx> fmt::Display for PatRange<'tcx> {
10251017/// If present, the const must be of a numeric type.
10261018#[ derive( Copy , Clone , Debug , PartialEq , HashStable , TypeVisitable ) ]
10271019pub enum PatRangeBoundary < ' tcx > {
1028- Finite ( mir :: Const < ' tcx > ) ,
1020+ Finite ( Ty < ' tcx > , ty :: ValTree < ' tcx > ) ,
10291021 NegInfinity ,
10301022 PosInfinity ,
10311023}
@@ -1036,20 +1028,15 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10361028 matches ! ( self , Self :: Finite ( ..) )
10371029 }
10381030 #[ inline]
1039- pub fn as_finite ( self ) -> Option < mir :: Const < ' tcx > > {
1031+ pub fn as_finite ( self ) -> Option < ty :: ValTree < ' tcx > > {
10401032 match self {
1041- Self :: Finite ( value) => Some ( value) ,
1033+ Self :: Finite ( _ty , value) => Some ( value) ,
10421034 Self :: NegInfinity | Self :: PosInfinity => None ,
10431035 }
10441036 }
1045- pub fn eval_bits (
1046- self ,
1047- ty : Ty < ' tcx > ,
1048- tcx : TyCtxt < ' tcx > ,
1049- typing_env : ty:: TypingEnv < ' tcx > ,
1050- ) -> u128 {
1037+ pub fn eval_bits ( self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> u128 {
10511038 match self {
1052- Self :: Finite ( value) => value. eval_bits ( tcx , typing_env ) ,
1039+ Self :: Finite ( _ty , value) => value. unwrap_leaf ( ) . to_bits_unchecked ( ) ,
10531040 Self :: NegInfinity => {
10541041 // Unwrap is ok because the type is known to be numeric.
10551042 ty. numeric_min_and_max_as_bits ( tcx) . unwrap ( ) . 0
@@ -1061,14 +1048,8 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10611048 }
10621049 }
10631050
1064- #[ instrument( skip( tcx, typing_env) , level = "debug" , ret) ]
1065- pub fn compare_with (
1066- self ,
1067- other : Self ,
1068- ty : Ty < ' tcx > ,
1069- tcx : TyCtxt < ' tcx > ,
1070- typing_env : ty:: TypingEnv < ' tcx > ,
1071- ) -> Option < Ordering > {
1051+ #[ instrument( skip( tcx) , level = "debug" , ret) ]
1052+ pub fn compare_with ( self , other : Self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Option < Ordering > {
10721053 use PatRangeBoundary :: * ;
10731054 match ( self , other) {
10741055 // When comparing with infinities, we must remember that `0u8..` and `0u8..=255`
@@ -1082,7 +1063,9 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10821063 // we can do scalar comparisons. E.g. `unicode-normalization` has
10831064 // many ranges such as '\u{037A}'..='\u{037F}', and chars can be compared
10841065 // in this way.
1085- ( Finite ( a) , Finite ( b) ) if matches ! ( ty. kind( ) , ty:: Int ( _) | ty:: Uint ( _) | ty:: Char ) => {
1066+ ( Finite ( _, a) , Finite ( _, b) )
1067+ if matches ! ( ty. kind( ) , ty:: Int ( _) | ty:: Uint ( _) | ty:: Char ) =>
1068+ {
10861069 if let ( Some ( a) , Some ( b) ) = ( a. try_to_scalar_int ( ) , b. try_to_scalar_int ( ) ) {
10871070 let sz = ty. primitive_size ( tcx) ;
10881071 let cmp = match ty. kind ( ) {
@@ -1096,8 +1079,8 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10961079 _ => { }
10971080 }
10981081
1099- let a = self . eval_bits ( ty, tcx, typing_env ) ;
1100- let b = other. eval_bits ( ty, tcx, typing_env ) ;
1082+ let a = self . eval_bits ( ty, tcx) ;
1083+ let b = other. eval_bits ( ty, tcx) ;
11011084
11021085 match ty. kind ( ) {
11031086 ty:: Float ( ty:: FloatTy :: F16 ) => {
0 commit comments