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