@@ -937,17 +937,17 @@ impl<'tcx> PatRange<'tcx> {
937
937
// Also, for performance, it's important to only do the second `try_to_bits` if necessary.
938
938
let lo_is_min = match self . lo {
939
939
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;
942
942
lo <= min
943
943
}
944
944
PatRangeBoundary :: PosInfinity => false ,
945
945
} ;
946
946
if lo_is_min {
947
947
let hi_is_max = match self . hi {
948
948
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;
951
951
hi > max || hi == max && self . end == RangeEnd :: Included
952
952
}
953
953
PatRangeBoundary :: PosInfinity => true ,
@@ -960,22 +960,16 @@ impl<'tcx> PatRange<'tcx> {
960
960
}
961
961
962
962
#[ 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 > {
969
964
use Ordering :: * ;
970
- debug_assert_eq ! ( self . ty, value. ty( ) ) ;
971
965
let ty = self . ty ;
972
- let value = PatRangeBoundary :: Finite ( value) ;
966
+ let value = PatRangeBoundary :: Finite ( ty , value) ;
973
967
// For performance, it's important to only do the second comparison if necessary.
974
968
Some (
975
- match self . lo . compare_with ( value, ty, tcx, typing_env ) ? {
969
+ match self . lo . compare_with ( value, ty, tcx) ? {
976
970
Less | Equal => true ,
977
971
Greater => false ,
978
- } && match value. compare_with ( self . hi , ty, tcx, typing_env ) ? {
972
+ } && match value. compare_with ( self . hi , ty, tcx) ? {
979
973
Less => true ,
980
974
Equal => self . end == RangeEnd :: Included ,
981
975
Greater => false ,
@@ -984,21 +978,16 @@ impl<'tcx> PatRange<'tcx> {
984
978
}
985
979
986
980
#[ 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 > {
993
982
use Ordering :: * ;
994
983
debug_assert_eq ! ( self . ty, other. ty) ;
995
984
// For performance, it's important to only do the second comparison if necessary.
996
985
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) ? {
998
987
Less => true ,
999
988
Equal => self . end == RangeEnd :: Included ,
1000
989
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) ? {
1002
991
Less => true ,
1003
992
Equal => other. end == RangeEnd :: Included ,
1004
993
Greater => false ,
@@ -1009,10 +998,13 @@ impl<'tcx> PatRange<'tcx> {
1009
998
1010
999
impl < ' tcx > fmt:: Display for PatRange < ' tcx > {
1011
1000
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 } ;
1013
1004
write ! ( f, "{value}" ) ?;
1014
1005
}
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 } ;
1016
1008
write ! ( f, "{}" , self . end) ?;
1017
1009
write ! ( f, "{value}" ) ?;
1018
1010
} else {
@@ -1027,7 +1019,7 @@ impl<'tcx> fmt::Display for PatRange<'tcx> {
1027
1019
/// If present, the const must be of a numeric type.
1028
1020
#[ derive( Copy , Clone , Debug , PartialEq , HashStable , TypeVisitable ) ]
1029
1021
pub enum PatRangeBoundary < ' tcx > {
1030
- Finite ( mir :: Const < ' tcx > ) ,
1022
+ Finite ( Ty < ' tcx > , ty :: ValTree < ' tcx > ) ,
1031
1023
NegInfinity ,
1032
1024
PosInfinity ,
1033
1025
}
@@ -1038,20 +1030,15 @@ impl<'tcx> PatRangeBoundary<'tcx> {
1038
1030
matches ! ( self , Self :: Finite ( ..) )
1039
1031
}
1040
1032
#[ inline]
1041
- pub fn as_finite ( self ) -> Option < mir :: Const < ' tcx > > {
1033
+ pub fn as_finite ( self ) -> Option < ty :: ValTree < ' tcx > > {
1042
1034
match self {
1043
- Self :: Finite ( value) => Some ( value) ,
1035
+ Self :: Finite ( _ty , value) => Some ( value) ,
1044
1036
Self :: NegInfinity | Self :: PosInfinity => None ,
1045
1037
}
1046
1038
}
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 {
1053
1040
match self {
1054
- Self :: Finite ( value) => value. eval_bits ( tcx , typing_env ) ,
1041
+ Self :: Finite ( _ty , value) => value. unwrap_leaf ( ) . to_bits_unchecked ( ) ,
1055
1042
Self :: NegInfinity => {
1056
1043
// Unwrap is ok because the type is known to be numeric.
1057
1044
ty. numeric_min_and_max_as_bits ( tcx) . unwrap ( ) . 0
@@ -1063,14 +1050,8 @@ impl<'tcx> PatRangeBoundary<'tcx> {
1063
1050
}
1064
1051
}
1065
1052
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 > {
1074
1055
use PatRangeBoundary :: * ;
1075
1056
match ( self , other) {
1076
1057
// When comparing with infinities, we must remember that `0u8..` and `0u8..=255`
@@ -1084,7 +1065,9 @@ impl<'tcx> PatRangeBoundary<'tcx> {
1084
1065
// we can do scalar comparisons. E.g. `unicode-normalization` has
1085
1066
// many ranges such as '\u{037A}'..='\u{037F}', and chars can be compared
1086
1067
// 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
+ {
1088
1071
if let ( Some ( a) , Some ( b) ) = ( a. try_to_scalar_int ( ) , b. try_to_scalar_int ( ) ) {
1089
1072
let sz = ty. primitive_size ( tcx) ;
1090
1073
let cmp = match ty. kind ( ) {
@@ -1098,8 +1081,8 @@ impl<'tcx> PatRangeBoundary<'tcx> {
1098
1081
_ => { }
1099
1082
}
1100
1083
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) ;
1103
1086
1104
1087
match ty. kind ( ) {
1105
1088
ty:: Float ( ty:: FloatTy :: F16 ) => {
0 commit comments