@@ -832,17 +832,17 @@ 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
/// * raw pointers derived from integers, other raw pointers will have already resulted in an
842
842
// error.
843
843
/// * `String`, if `string_deref_patterns` is enabled.
844
844
Constant {
845
- value : mir :: Const < ' tcx > ,
845
+ value : ty :: Value < ' tcx > ,
846
846
} ,
847
847
848
848
/// Pattern obtained by converting a constant (inline or named) to its pattern
@@ -935,7 +935,7 @@ impl<'tcx> PatRange<'tcx> {
935
935
let lo_is_min = match self . lo {
936
936
PatRangeBoundary :: NegInfinity => true ,
937
937
PatRangeBoundary :: Finite ( value) => {
938
- let lo = value. try_to_bits ( size ) . unwrap ( ) ^ bias;
938
+ let lo = value. try_to_scalar_int ( ) . unwrap ( ) . to_bits ( size ) ^ bias;
939
939
lo <= min
940
940
}
941
941
PatRangeBoundary :: PosInfinity => false ,
@@ -944,7 +944,7 @@ impl<'tcx> PatRange<'tcx> {
944
944
let hi_is_max = match self . hi {
945
945
PatRangeBoundary :: NegInfinity => false ,
946
946
PatRangeBoundary :: Finite ( value) => {
947
- let hi = value. try_to_bits ( size ) . unwrap ( ) ^ bias;
947
+ let hi = value. try_to_scalar_int ( ) . unwrap ( ) . to_bits ( size ) ^ bias;
948
948
hi > max || hi == max && self . end == RangeEnd :: Included
949
949
}
950
950
PatRangeBoundary :: PosInfinity => true ,
@@ -957,22 +957,16 @@ impl<'tcx> PatRange<'tcx> {
957
957
}
958
958
959
959
#[ inline]
960
- pub fn contains (
961
- & self ,
962
- value : mir:: Const < ' tcx > ,
963
- tcx : TyCtxt < ' tcx > ,
964
- typing_env : ty:: TypingEnv < ' tcx > ,
965
- ) -> Option < bool > {
960
+ pub fn contains ( & self , valtree : ty:: ValTree < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Option < bool > {
966
961
use Ordering :: * ;
967
- debug_assert_eq ! ( self . ty, value. ty( ) ) ;
968
962
let ty = self . ty ;
969
- let value = PatRangeBoundary :: Finite ( value ) ;
963
+ let value = PatRangeBoundary :: Finite ( valtree ) ;
970
964
// For performance, it's important to only do the second comparison if necessary.
971
965
Some (
972
- match self . lo . compare_with ( value, ty, tcx, typing_env ) ? {
966
+ match self . lo . compare_with ( value, ty, tcx) ? {
973
967
Less | Equal => true ,
974
968
Greater => false ,
975
- } && match value. compare_with ( self . hi , ty, tcx, typing_env ) ? {
969
+ } && match value. compare_with ( self . hi , ty, tcx) ? {
976
970
Less => true ,
977
971
Equal => self . end == RangeEnd :: Included ,
978
972
Greater => false ,
@@ -981,21 +975,16 @@ impl<'tcx> PatRange<'tcx> {
981
975
}
982
976
983
977
#[ inline]
984
- pub fn overlaps (
985
- & self ,
986
- other : & Self ,
987
- tcx : TyCtxt < ' tcx > ,
988
- typing_env : ty:: TypingEnv < ' tcx > ,
989
- ) -> Option < bool > {
978
+ pub fn overlaps ( & self , other : & Self , tcx : TyCtxt < ' tcx > ) -> Option < bool > {
990
979
use Ordering :: * ;
991
980
debug_assert_eq ! ( self . ty, other. ty) ;
992
981
// For performance, it's important to only do the second comparison if necessary.
993
982
Some (
994
- match other. lo . compare_with ( self . hi , self . ty , tcx, typing_env ) ? {
983
+ match other. lo . compare_with ( self . hi , self . ty , tcx) ? {
995
984
Less => true ,
996
985
Equal => self . end == RangeEnd :: Included ,
997
986
Greater => false ,
998
- } && match self . lo . compare_with ( other. hi , self . ty , tcx, typing_env ) ? {
987
+ } && match self . lo . compare_with ( other. hi , self . ty , tcx) ? {
999
988
Less => true ,
1000
989
Equal => other. end == RangeEnd :: Included ,
1001
990
Greater => false ,
@@ -1006,11 +995,13 @@ impl<'tcx> PatRange<'tcx> {
1006
995
1007
996
impl < ' tcx > fmt:: Display for PatRange < ' tcx > {
1008
997
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1009
- if let PatRangeBoundary :: Finite ( value) = & self . lo {
998
+ if let & PatRangeBoundary :: Finite ( valtree) = & self . lo {
999
+ let value = ty:: Value { ty : self . ty , valtree } ;
1010
1000
write ! ( f, "{value}" ) ?;
1011
1001
}
1012
- if let PatRangeBoundary :: Finite ( value ) = & self . hi {
1002
+ if let & PatRangeBoundary :: Finite ( valtree ) = & self . hi {
1013
1003
write ! ( f, "{}" , self . end) ?;
1004
+ let value = ty:: Value { ty : self . ty , valtree } ;
1014
1005
write ! ( f, "{value}" ) ?;
1015
1006
} else {
1016
1007
// `0..` is parsed as an inclusive range, we must display it correctly.
@@ -1024,7 +1015,8 @@ impl<'tcx> fmt::Display for PatRange<'tcx> {
1024
1015
/// If present, the const must be of a numeric type.
1025
1016
#[ derive( Copy , Clone , Debug , PartialEq , HashStable , TypeVisitable ) ]
1026
1017
pub enum PatRangeBoundary < ' tcx > {
1027
- Finite ( mir:: Const < ' tcx > ) ,
1018
+ /// The type if this valtree is stored in the surrounding `PatRange`.
1019
+ Finite ( ty:: ValTree < ' tcx > ) ,
1028
1020
NegInfinity ,
1029
1021
PosInfinity ,
1030
1022
}
@@ -1035,20 +1027,15 @@ impl<'tcx> PatRangeBoundary<'tcx> {
1035
1027
matches ! ( self , Self :: Finite ( ..) )
1036
1028
}
1037
1029
#[ inline]
1038
- pub fn as_finite ( self ) -> Option < mir :: Const < ' tcx > > {
1030
+ pub fn as_finite ( self ) -> Option < ty :: ValTree < ' tcx > > {
1039
1031
match self {
1040
1032
Self :: Finite ( value) => Some ( value) ,
1041
1033
Self :: NegInfinity | Self :: PosInfinity => None ,
1042
1034
}
1043
1035
}
1044
- pub fn eval_bits (
1045
- self ,
1046
- ty : Ty < ' tcx > ,
1047
- tcx : TyCtxt < ' tcx > ,
1048
- typing_env : ty:: TypingEnv < ' tcx > ,
1049
- ) -> u128 {
1036
+ pub fn eval_bits ( self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> u128 {
1050
1037
match self {
1051
- Self :: Finite ( value) => value. eval_bits ( tcx , typing_env ) ,
1038
+ Self :: Finite ( value) => value. try_to_scalar_int ( ) . unwrap ( ) . to_bits_unchecked ( ) ,
1052
1039
Self :: NegInfinity => {
1053
1040
// Unwrap is ok because the type is known to be numeric.
1054
1041
ty. numeric_min_and_max_as_bits ( tcx) . unwrap ( ) . 0
@@ -1060,14 +1047,8 @@ impl<'tcx> PatRangeBoundary<'tcx> {
1060
1047
}
1061
1048
}
1062
1049
1063
- #[ instrument( skip( tcx, typing_env) , level = "debug" , ret) ]
1064
- pub fn compare_with (
1065
- self ,
1066
- other : Self ,
1067
- ty : Ty < ' tcx > ,
1068
- tcx : TyCtxt < ' tcx > ,
1069
- typing_env : ty:: TypingEnv < ' tcx > ,
1070
- ) -> Option < Ordering > {
1050
+ #[ instrument( skip( tcx) , level = "debug" , ret) ]
1051
+ pub fn compare_with ( self , other : Self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Option < Ordering > {
1071
1052
use PatRangeBoundary :: * ;
1072
1053
match ( self , other) {
1073
1054
// When comparing with infinities, we must remember that `0u8..` and `0u8..=255`
@@ -1095,8 +1076,8 @@ impl<'tcx> PatRangeBoundary<'tcx> {
1095
1076
_ => { }
1096
1077
}
1097
1078
1098
- let a = self . eval_bits ( ty, tcx, typing_env ) ;
1099
- let b = other. eval_bits ( ty, tcx, typing_env ) ;
1079
+ let a = self . eval_bits ( ty, tcx) ;
1080
+ let b = other. eval_bits ( ty, tcx) ;
1100
1081
1101
1082
match ty. kind ( ) {
1102
1083
ty:: Float ( ty:: FloatTy :: F16 ) => {
0 commit comments