@@ -832,17 +832,17 @@ pub enum PatKind<'tcx> {
832832 } ,
833833
834834 /// 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
836836 /// exhaustiveness checking will detect if you use the same string twice in different
837837 /// 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
839839 /// exhaustiveness to cover exactly its own value, similar to `&str`, but these values are
840840 /// much simpler.
841841 /// * raw pointers derived from integers, other raw pointers will have already resulted in an
842842 // error.
843843 /// * `String`, if `string_deref_patterns` is enabled.
844844 Constant {
845- value : mir :: Const < ' tcx > ,
845+ value : ty :: Value < ' tcx > ,
846846 } ,
847847
848848 /// Pattern obtained by converting a constant (inline or named) to its pattern
@@ -935,7 +935,7 @@ impl<'tcx> PatRange<'tcx> {
935935 let lo_is_min = match self . lo {
936936 PatRangeBoundary :: NegInfinity => true ,
937937 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;
939939 lo <= min
940940 }
941941 PatRangeBoundary :: PosInfinity => false ,
@@ -944,7 +944,7 @@ impl<'tcx> PatRange<'tcx> {
944944 let hi_is_max = match self . hi {
945945 PatRangeBoundary :: NegInfinity => false ,
946946 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;
948948 hi > max || hi == max && self . end == RangeEnd :: Included
949949 }
950950 PatRangeBoundary :: PosInfinity => true ,
@@ -957,22 +957,17 @@ impl<'tcx> PatRange<'tcx> {
957957 }
958958
959959 #[ 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 , value : ty:: Value < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Option < bool > {
966961 use Ordering :: * ;
967- debug_assert_eq ! ( self . ty, value . ty( ) ) ;
962+ debug_assert_eq ! ( value . ty, self . ty) ;
968963 let ty = self . ty ;
969- let value = PatRangeBoundary :: Finite ( value) ;
964+ let value = PatRangeBoundary :: Finite ( value. valtree ) ;
970965 // For performance, it's important to only do the second comparison if necessary.
971966 Some (
972- match self . lo . compare_with ( value, ty, tcx, typing_env ) ? {
967+ match self . lo . compare_with ( value, ty, tcx) ? {
973968 Less | Equal => true ,
974969 Greater => false ,
975- } && match value. compare_with ( self . hi , ty, tcx, typing_env ) ? {
970+ } && match value. compare_with ( self . hi , ty, tcx) ? {
976971 Less => true ,
977972 Equal => self . end == RangeEnd :: Included ,
978973 Greater => false ,
@@ -981,21 +976,16 @@ impl<'tcx> PatRange<'tcx> {
981976 }
982977
983978 #[ inline]
984- pub fn overlaps (
985- & self ,
986- other : & Self ,
987- tcx : TyCtxt < ' tcx > ,
988- typing_env : ty:: TypingEnv < ' tcx > ,
989- ) -> Option < bool > {
979+ pub fn overlaps ( & self , other : & Self , tcx : TyCtxt < ' tcx > ) -> Option < bool > {
990980 use Ordering :: * ;
991981 debug_assert_eq ! ( self . ty, other. ty) ;
992982 // For performance, it's important to only do the second comparison if necessary.
993983 Some (
994- match other. lo . compare_with ( self . hi , self . ty , tcx, typing_env ) ? {
984+ match other. lo . compare_with ( self . hi , self . ty , tcx) ? {
995985 Less => true ,
996986 Equal => self . end == RangeEnd :: Included ,
997987 Greater => false ,
998- } && match self . lo . compare_with ( other. hi , self . ty , tcx, typing_env ) ? {
988+ } && match self . lo . compare_with ( other. hi , self . ty , tcx) ? {
999989 Less => true ,
1000990 Equal => other. end == RangeEnd :: Included ,
1001991 Greater => false ,
@@ -1006,11 +996,13 @@ impl<'tcx> PatRange<'tcx> {
1006996
1007997impl < ' tcx > fmt:: Display for PatRange < ' tcx > {
1008998 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1009- if let PatRangeBoundary :: Finite ( value) = & self . lo {
999+ if let & PatRangeBoundary :: Finite ( valtree) = & self . lo {
1000+ let value = ty:: Value { ty : self . ty , valtree } ;
10101001 write ! ( f, "{value}" ) ?;
10111002 }
1012- if let PatRangeBoundary :: Finite ( value ) = & self . hi {
1003+ if let & PatRangeBoundary :: Finite ( valtree ) = & self . hi {
10131004 write ! ( f, "{}" , self . end) ?;
1005+ let value = ty:: Value { ty : self . ty , valtree } ;
10141006 write ! ( f, "{value}" ) ?;
10151007 } else {
10161008 // `0..` is parsed as an inclusive range, we must display it correctly.
@@ -1024,7 +1016,8 @@ impl<'tcx> fmt::Display for PatRange<'tcx> {
10241016/// If present, the const must be of a numeric type.
10251017#[ derive( Copy , Clone , Debug , PartialEq , HashStable , TypeVisitable ) ]
10261018pub enum PatRangeBoundary < ' tcx > {
1027- Finite ( mir:: Const < ' tcx > ) ,
1019+ /// The type of this valtree is stored in the surrounding `PatRange`.
1020+ Finite ( ty:: ValTree < ' tcx > ) ,
10281021 NegInfinity ,
10291022 PosInfinity ,
10301023}
@@ -1035,20 +1028,15 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10351028 matches ! ( self , Self :: Finite ( ..) )
10361029 }
10371030 #[ inline]
1038- pub fn as_finite ( self ) -> Option < mir :: Const < ' tcx > > {
1031+ pub fn as_finite ( self ) -> Option < ty :: ValTree < ' tcx > > {
10391032 match self {
10401033 Self :: Finite ( value) => Some ( value) ,
10411034 Self :: NegInfinity | Self :: PosInfinity => None ,
10421035 }
10431036 }
1044- pub fn eval_bits (
1045- self ,
1046- ty : Ty < ' tcx > ,
1047- tcx : TyCtxt < ' tcx > ,
1048- typing_env : ty:: TypingEnv < ' tcx > ,
1049- ) -> u128 {
1037+ pub fn to_bits ( self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> u128 {
10501038 match self {
1051- Self :: Finite ( value) => value. eval_bits ( tcx , typing_env ) ,
1039+ Self :: Finite ( value) => value. try_to_scalar_int ( ) . unwrap ( ) . to_bits_unchecked ( ) ,
10521040 Self :: NegInfinity => {
10531041 // Unwrap is ok because the type is known to be numeric.
10541042 ty. numeric_min_and_max_as_bits ( tcx) . unwrap ( ) . 0
@@ -1060,14 +1048,8 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10601048 }
10611049 }
10621050
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 > {
1051+ #[ instrument( skip( tcx) , level = "debug" , ret) ]
1052+ pub fn compare_with ( self , other : Self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Option < Ordering > {
10711053 use PatRangeBoundary :: * ;
10721054 match ( self , other) {
10731055 // When comparing with infinities, we must remember that `0u8..` and `0u8..=255`
@@ -1095,8 +1077,8 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10951077 _ => { }
10961078 }
10971079
1098- let a = self . eval_bits ( ty, tcx, typing_env ) ;
1099- let b = other. eval_bits ( ty, tcx, typing_env ) ;
1080+ let a = self . to_bits ( ty, tcx) ;
1081+ let b = other. to_bits ( ty, tcx) ;
11001082
11011083 match ty. kind ( ) {
11021084 ty:: Float ( ty:: FloatTy :: F16 ) => {
0 commit comments