@@ -832,15 +832,15 @@ pub enum PatKind<'tcx> {
832
832
} ,
833
833
834
834
/// One of the following:
835
- /// * `&str` (represented as a valtree) , which will be handled as a string pattern and thus
835
+ /// * `&str`, which will be handled as a string pattern and thus
836
836
/// exhaustiveness checking will detect if you use the same string twice in different
837
837
/// patterns.
838
- /// * integer, bool, char or float (represented as a valtree) , which will be handled by
838
+ /// * integer, bool, char or float, which will be handled by
839
839
/// exhaustiveness to cover exactly its own value, similar to `&str`, but these values are
840
840
/// much simpler.
841
841
/// * `String`, if `string_deref_patterns` is enabled.
842
842
Constant {
843
- value : mir :: Const < ' tcx > ,
843
+ value : ty :: Value < ' tcx > ,
844
844
} ,
845
845
846
846
/// Pattern obtained by converting a constant (inline or named) to its pattern
@@ -933,7 +933,7 @@ impl<'tcx> PatRange<'tcx> {
933
933
let lo_is_min = match self . lo {
934
934
PatRangeBoundary :: NegInfinity => true ,
935
935
PatRangeBoundary :: Finite ( value) => {
936
- let lo = value. try_to_bits ( size ) . unwrap ( ) ^ bias;
936
+ let lo = value. try_to_scalar_int ( ) . unwrap ( ) . to_bits ( size ) ^ bias;
937
937
lo <= min
938
938
}
939
939
PatRangeBoundary :: PosInfinity => false ,
@@ -942,7 +942,7 @@ impl<'tcx> PatRange<'tcx> {
942
942
let hi_is_max = match self . hi {
943
943
PatRangeBoundary :: NegInfinity => false ,
944
944
PatRangeBoundary :: Finite ( value) => {
945
- let hi = value. try_to_bits ( size ) . unwrap ( ) ^ bias;
945
+ let hi = value. try_to_scalar_int ( ) . unwrap ( ) . to_bits ( size ) ^ bias;
946
946
hi > max || hi == max && self . end == RangeEnd :: Included
947
947
}
948
948
PatRangeBoundary :: PosInfinity => true ,
@@ -955,22 +955,17 @@ impl<'tcx> PatRange<'tcx> {
955
955
}
956
956
957
957
#[ inline]
958
- pub fn contains (
959
- & self ,
960
- value : mir:: Const < ' tcx > ,
961
- tcx : TyCtxt < ' tcx > ,
962
- typing_env : ty:: TypingEnv < ' tcx > ,
963
- ) -> Option < bool > {
958
+ pub fn contains ( & self , value : ty:: Value < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Option < bool > {
964
959
use Ordering :: * ;
965
- debug_assert_eq ! ( self . ty, value. ty( ) ) ;
960
+ debug_assert_eq ! ( self . ty, value. ty) ;
966
961
let ty = self . ty ;
967
962
let value = PatRangeBoundary :: Finite ( value) ;
968
963
// For performance, it's important to only do the second comparison if necessary.
969
964
Some (
970
- match self . lo . compare_with ( value, ty, tcx, typing_env ) ? {
965
+ match self . lo . compare_with ( value, ty, tcx) ? {
971
966
Less | Equal => true ,
972
967
Greater => false ,
973
- } && match value. compare_with ( self . hi , ty, tcx, typing_env ) ? {
968
+ } && match value. compare_with ( self . hi , ty, tcx) ? {
974
969
Less => true ,
975
970
Equal => self . end == RangeEnd :: Included ,
976
971
Greater => false ,
@@ -979,21 +974,16 @@ impl<'tcx> PatRange<'tcx> {
979
974
}
980
975
981
976
#[ inline]
982
- pub fn overlaps (
983
- & self ,
984
- other : & Self ,
985
- tcx : TyCtxt < ' tcx > ,
986
- typing_env : ty:: TypingEnv < ' tcx > ,
987
- ) -> Option < bool > {
977
+ pub fn overlaps ( & self , other : & Self , tcx : TyCtxt < ' tcx > ) -> Option < bool > {
988
978
use Ordering :: * ;
989
979
debug_assert_eq ! ( self . ty, other. ty) ;
990
980
// For performance, it's important to only do the second comparison if necessary.
991
981
Some (
992
- match other. lo . compare_with ( self . hi , self . ty , tcx, typing_env ) ? {
982
+ match other. lo . compare_with ( self . hi , self . ty , tcx) ? {
993
983
Less => true ,
994
984
Equal => self . end == RangeEnd :: Included ,
995
985
Greater => false ,
996
- } && match self . lo . compare_with ( other. hi , self . ty , tcx, typing_env ) ? {
986
+ } && match self . lo . compare_with ( other. hi , self . ty , tcx) ? {
997
987
Less => true ,
998
988
Equal => other. end == RangeEnd :: Included ,
999
989
Greater => false ,
@@ -1022,7 +1012,7 @@ impl<'tcx> fmt::Display for PatRange<'tcx> {
1022
1012
/// If present, the const must be of a numeric type.
1023
1013
#[ derive( Copy , Clone , Debug , PartialEq , HashStable , TypeVisitable ) ]
1024
1014
pub enum PatRangeBoundary < ' tcx > {
1025
- Finite ( mir :: Const < ' tcx > ) ,
1015
+ Finite ( ty :: Value < ' tcx > ) ,
1026
1016
NegInfinity ,
1027
1017
PosInfinity ,
1028
1018
}
@@ -1033,20 +1023,15 @@ impl<'tcx> PatRangeBoundary<'tcx> {
1033
1023
matches ! ( self , Self :: Finite ( ..) )
1034
1024
}
1035
1025
#[ inline]
1036
- pub fn as_finite ( self ) -> Option < mir :: Const < ' tcx > > {
1026
+ pub fn as_finite ( self ) -> Option < ty :: Value < ' tcx > > {
1037
1027
match self {
1038
1028
Self :: Finite ( value) => Some ( value) ,
1039
1029
Self :: NegInfinity | Self :: PosInfinity => None ,
1040
1030
}
1041
1031
}
1042
- pub fn eval_bits (
1043
- self ,
1044
- ty : Ty < ' tcx > ,
1045
- tcx : TyCtxt < ' tcx > ,
1046
- typing_env : ty:: TypingEnv < ' tcx > ,
1047
- ) -> u128 {
1032
+ pub fn eval_bits ( self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> u128 {
1048
1033
match self {
1049
- Self :: Finite ( value) => value. eval_bits ( tcx , typing_env ) ,
1034
+ Self :: Finite ( value) => value. try_to_scalar_int ( ) . unwrap ( ) . to_bits_unchecked ( ) ,
1050
1035
Self :: NegInfinity => {
1051
1036
// Unwrap is ok because the type is known to be numeric.
1052
1037
ty. numeric_min_and_max_as_bits ( tcx) . unwrap ( ) . 0
@@ -1058,14 +1043,8 @@ impl<'tcx> PatRangeBoundary<'tcx> {
1058
1043
}
1059
1044
}
1060
1045
1061
- #[ instrument( skip( tcx, typing_env) , level = "debug" , ret) ]
1062
- pub fn compare_with (
1063
- self ,
1064
- other : Self ,
1065
- ty : Ty < ' tcx > ,
1066
- tcx : TyCtxt < ' tcx > ,
1067
- typing_env : ty:: TypingEnv < ' tcx > ,
1068
- ) -> Option < Ordering > {
1046
+ #[ instrument( skip( tcx) , level = "debug" , ret) ]
1047
+ pub fn compare_with ( self , other : Self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Option < Ordering > {
1069
1048
use PatRangeBoundary :: * ;
1070
1049
match ( self , other) {
1071
1050
// When comparing with infinities, we must remember that `0u8..` and `0u8..=255`
@@ -1093,8 +1072,8 @@ impl<'tcx> PatRangeBoundary<'tcx> {
1093
1072
_ => { }
1094
1073
}
1095
1074
1096
- let a = self . eval_bits ( ty, tcx, typing_env ) ;
1097
- let b = other. eval_bits ( ty, tcx, typing_env ) ;
1075
+ let a = self . eval_bits ( ty, tcx) ;
1076
+ let b = other. eval_bits ( ty, tcx) ;
1098
1077
1099
1078
match ty. kind ( ) {
1100
1079
ty:: Float ( ty:: FloatTy :: F16 ) => {
0 commit comments