@@ -842,10 +842,7 @@ pub enum PatKind<'tcx> {
842842 // error.
843843 /// * `String`, if `string_deref_patterns` is enabled.
844844 Constant {
845- // Not using `ty::Value` since this is conceptually not a type-level constant. In
846- // particular, it can have raw pointers.
847- ty : Ty < ' tcx > ,
848- value : ty:: ValTree < ' tcx > ,
845+ value : ty:: Value < ' tcx > ,
849846 } ,
850847
851848 /// Pattern obtained by converting a constant (inline or named) to its pattern
@@ -937,17 +934,17 @@ impl<'tcx> PatRange<'tcx> {
937934 // Also, for performance, it's important to only do the second `try_to_bits` if necessary.
938935 let lo_is_min = match self . lo {
939936 PatRangeBoundary :: NegInfinity => true ,
940- PatRangeBoundary :: Finite ( _ty , value) => {
941- let lo = value. unwrap_leaf ( ) . to_bits ( size) ^ bias;
937+ PatRangeBoundary :: Finite ( value) => {
938+ let lo = value. try_to_scalar_int ( ) . unwrap ( ) . to_bits ( size) ^ bias;
942939 lo <= min
943940 }
944941 PatRangeBoundary :: PosInfinity => false ,
945942 } ;
946943 if lo_is_min {
947944 let hi_is_max = match self . hi {
948945 PatRangeBoundary :: NegInfinity => false ,
949- PatRangeBoundary :: Finite ( _ty , value) => {
950- let hi = value. unwrap_leaf ( ) . to_bits ( size) ^ bias;
946+ PatRangeBoundary :: Finite ( value) => {
947+ let hi = value. try_to_scalar_int ( ) . unwrap ( ) . to_bits ( size) ^ bias;
951948 hi > max || hi == max && self . end == RangeEnd :: Included
952949 }
953950 PatRangeBoundary :: PosInfinity => true ,
@@ -960,10 +957,11 @@ impl<'tcx> PatRange<'tcx> {
960957 }
961958
962959 #[ inline]
963- pub fn contains ( & self , value : ty:: ValTree < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Option < bool > {
960+ pub fn contains ( & self , value : ty:: Value < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Option < bool > {
964961 use Ordering :: * ;
962+ debug_assert_eq ! ( self . ty, value. ty) ;
965963 let ty = self . ty ;
966- let value = PatRangeBoundary :: Finite ( ty , value) ;
964+ let value = PatRangeBoundary :: Finite ( value) ;
967965 // For performance, it's important to only do the second comparison if necessary.
968966 Some (
969967 match self . lo . compare_with ( value, ty, tcx) ? {
@@ -998,13 +996,10 @@ impl<'tcx> PatRange<'tcx> {
998996
999997impl < ' tcx > fmt:: Display for PatRange < ' tcx > {
1000998 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1001- if let & PatRangeBoundary :: Finite ( ty, value) = & self . lo {
1002- // `ty::Value` has a reasonable pretty-printing implementation.
1003- let value = ty:: Value { ty, valtree : value } ;
999+ if let PatRangeBoundary :: Finite ( value) = & self . lo {
10041000 write ! ( f, "{value}" ) ?;
10051001 }
1006- if let & PatRangeBoundary :: Finite ( ty, value) = & self . hi {
1007- let value = ty:: Value { ty, valtree : value } ;
1002+ if let PatRangeBoundary :: Finite ( value) = & self . hi {
10081003 write ! ( f, "{}" , self . end) ?;
10091004 write ! ( f, "{value}" ) ?;
10101005 } else {
@@ -1019,7 +1014,7 @@ impl<'tcx> fmt::Display for PatRange<'tcx> {
10191014/// If present, the const must be of a numeric type.
10201015#[ derive( Copy , Clone , Debug , PartialEq , HashStable , TypeVisitable ) ]
10211016pub enum PatRangeBoundary < ' tcx > {
1022- Finite ( Ty < ' tcx > , ty:: ValTree < ' tcx > ) ,
1017+ Finite ( ty:: Value < ' tcx > ) ,
10231018 NegInfinity ,
10241019 PosInfinity ,
10251020}
@@ -1030,15 +1025,15 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10301025 matches ! ( self , Self :: Finite ( ..) )
10311026 }
10321027 #[ inline]
1033- pub fn as_finite ( self ) -> Option < ty:: ValTree < ' tcx > > {
1028+ pub fn as_finite ( self ) -> Option < ty:: Value < ' tcx > > {
10341029 match self {
1035- Self :: Finite ( _ty , value) => Some ( value) ,
1030+ Self :: Finite ( value) => Some ( value) ,
10361031 Self :: NegInfinity | Self :: PosInfinity => None ,
10371032 }
10381033 }
10391034 pub fn eval_bits ( self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> u128 {
10401035 match self {
1041- Self :: Finite ( _ty , value) => value. unwrap_leaf ( ) . to_bits_unchecked ( ) ,
1036+ Self :: Finite ( value) => value. try_to_scalar_int ( ) . unwrap ( ) . to_bits_unchecked ( ) ,
10421037 Self :: NegInfinity => {
10431038 // Unwrap is ok because the type is known to be numeric.
10441039 ty. numeric_min_and_max_as_bits ( tcx) . unwrap ( ) . 0
@@ -1065,9 +1060,7 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10651060 // we can do scalar comparisons. E.g. `unicode-normalization` has
10661061 // many ranges such as '\u{037A}'..='\u{037F}', and chars can be compared
10671062 // in this way.
1068- ( Finite ( _, a) , Finite ( _, b) )
1069- if matches ! ( ty. kind( ) , ty:: Int ( _) | ty:: Uint ( _) | ty:: Char ) =>
1070- {
1063+ ( Finite ( a) , Finite ( b) ) if matches ! ( ty. kind( ) , ty:: Int ( _) | ty:: Uint ( _) | ty:: Char ) => {
10711064 if let ( Some ( a) , Some ( b) ) = ( a. try_to_scalar_int ( ) , b. try_to_scalar_int ( ) ) {
10721065 let sz = ty. primitive_size ( tcx) ;
10731066 let cmp = match ty. kind ( ) {
0 commit comments