@@ -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,16 @@ 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 , valtree : ty:: ValTree < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Option < bool > {
966961 use Ordering :: * ;
967- debug_assert_eq ! ( self . ty, value. ty( ) ) ;
968962 let ty = self . ty ;
969- let value = PatRangeBoundary :: Finite ( value ) ;
963+ let value = PatRangeBoundary :: Finite ( ty :: Value { ty , valtree } ) ;
970964 // For performance, it's important to only do the second comparison if necessary.
971965 Some (
972- match self . lo . compare_with ( value, ty, tcx, typing_env ) ? {
966+ match self . lo . compare_with ( value, ty, tcx) ? {
973967 Less | Equal => true ,
974968 Greater => false ,
975- } && match value. compare_with ( self . hi , ty, tcx, typing_env ) ? {
969+ } && match value. compare_with ( self . hi , ty, tcx) ? {
976970 Less => true ,
977971 Equal => self . end == RangeEnd :: Included ,
978972 Greater => false ,
@@ -981,21 +975,16 @@ impl<'tcx> PatRange<'tcx> {
981975 }
982976
983977 #[ 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 > {
990979 use Ordering :: * ;
991980 debug_assert_eq ! ( self . ty, other. ty) ;
992981 // For performance, it's important to only do the second comparison if necessary.
993982 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) ? {
995984 Less => true ,
996985 Equal => self . end == RangeEnd :: Included ,
997986 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) ? {
999988 Less => true ,
1000989 Equal => other. end == RangeEnd :: Included ,
1001990 Greater => false ,
@@ -1024,7 +1013,7 @@ impl<'tcx> fmt::Display for PatRange<'tcx> {
10241013/// If present, the const must be of a numeric type.
10251014#[ derive( Copy , Clone , Debug , PartialEq , HashStable , TypeVisitable ) ]
10261015pub enum PatRangeBoundary < ' tcx > {
1027- Finite ( mir :: Const < ' tcx > ) ,
1016+ Finite ( ty :: Value < ' tcx > ) ,
10281017 NegInfinity ,
10291018 PosInfinity ,
10301019}
@@ -1035,20 +1024,15 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10351024 matches ! ( self , Self :: Finite ( ..) )
10361025 }
10371026 #[ inline]
1038- pub fn as_finite ( self ) -> Option < mir :: Const < ' tcx > > {
1027+ pub fn as_finite ( self ) -> Option < ty :: Value < ' tcx > > {
10391028 match self {
10401029 Self :: Finite ( value) => Some ( value) ,
10411030 Self :: NegInfinity | Self :: PosInfinity => None ,
10421031 }
10431032 }
1044- pub fn eval_bits (
1045- self ,
1046- ty : Ty < ' tcx > ,
1047- tcx : TyCtxt < ' tcx > ,
1048- typing_env : ty:: TypingEnv < ' tcx > ,
1049- ) -> u128 {
1033+ pub fn eval_bits ( self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> u128 {
10501034 match self {
1051- Self :: Finite ( value) => value. eval_bits ( tcx , typing_env ) ,
1035+ Self :: Finite ( value) => value. try_to_scalar_int ( ) . unwrap ( ) . to_bits_unchecked ( ) ,
10521036 Self :: NegInfinity => {
10531037 // Unwrap is ok because the type is known to be numeric.
10541038 ty. numeric_min_and_max_as_bits ( tcx) . unwrap ( ) . 0
@@ -1060,14 +1044,8 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10601044 }
10611045 }
10621046
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 > {
1047+ #[ instrument( skip( tcx) , level = "debug" , ret) ]
1048+ pub fn compare_with ( self , other : Self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Option < Ordering > {
10711049 use PatRangeBoundary :: * ;
10721050 match ( self , other) {
10731051 // When comparing with infinities, we must remember that `0u8..` and `0u8..=255`
@@ -1095,8 +1073,8 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10951073 _ => { }
10961074 }
10971075
1098- let a = self . eval_bits ( ty, tcx, typing_env ) ;
1099- let b = other. eval_bits ( ty, tcx, typing_env ) ;
1076+ let a = self . eval_bits ( ty, tcx) ;
1077+ let b = other. eval_bits ( ty, tcx) ;
11001078
11011079 match ty. kind ( ) {
11021080 ty:: Float ( ty:: FloatTy :: F16 ) => {
0 commit comments