@@ -840,10 +840,7 @@ pub enum PatKind<'tcx> {
840840 /// much simpler.
841841 /// * `String`, if `string_deref_patterns` is enabled.
842842 Constant {
843- // Not using `ty::Value` since this is conceptually not a type-level constant. In
844- // particular, it can have raw pointers.
845- ty : Ty < ' tcx > ,
846- value : ty:: ValTree < ' tcx > ,
843+ value : ty:: Value < ' tcx > ,
847844 } ,
848845
849846 /// Pattern obtained by converting a constant (inline or named) to its pattern
@@ -935,17 +932,17 @@ impl<'tcx> PatRange<'tcx> {
935932 // Also, for performance, it's important to only do the second `try_to_bits` if necessary.
936933 let lo_is_min = match self . lo {
937934 PatRangeBoundary :: NegInfinity => true ,
938- PatRangeBoundary :: Finite ( _ty , value) => {
939- let lo = value. unwrap_leaf ( ) . to_bits ( size) ^ bias;
935+ PatRangeBoundary :: Finite ( value) => {
936+ let lo = value. try_to_scalar_int ( ) . unwrap ( ) . to_bits ( size) ^ bias;
940937 lo <= min
941938 }
942939 PatRangeBoundary :: PosInfinity => false ,
943940 } ;
944941 if lo_is_min {
945942 let hi_is_max = match self . hi {
946943 PatRangeBoundary :: NegInfinity => false ,
947- PatRangeBoundary :: Finite ( _ty , value) => {
948- let hi = value. unwrap_leaf ( ) . to_bits ( size) ^ bias;
944+ PatRangeBoundary :: Finite ( value) => {
945+ let hi = value. try_to_scalar_int ( ) . unwrap ( ) . to_bits ( size) ^ bias;
949946 hi > max || hi == max && self . end == RangeEnd :: Included
950947 }
951948 PatRangeBoundary :: PosInfinity => true ,
@@ -958,10 +955,11 @@ impl<'tcx> PatRange<'tcx> {
958955 }
959956
960957 #[ inline]
961- pub fn contains ( & self , value : ty:: ValTree < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Option < bool > {
958+ pub fn contains ( & self , value : ty:: Value < ' tcx > , tcx : TyCtxt < ' tcx > ) -> Option < bool > {
962959 use Ordering :: * ;
960+ debug_assert_eq ! ( self . ty, value. ty) ;
963961 let ty = self . ty ;
964- let value = PatRangeBoundary :: Finite ( ty , value) ;
962+ let value = PatRangeBoundary :: Finite ( value) ;
965963 // For performance, it's important to only do the second comparison if necessary.
966964 Some (
967965 match self . lo . compare_with ( value, ty, tcx) ? {
@@ -996,13 +994,10 @@ impl<'tcx> PatRange<'tcx> {
996994
997995impl < ' tcx > fmt:: Display for PatRange < ' tcx > {
998996 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
999- if let & PatRangeBoundary :: Finite ( ty, value) = & self . lo {
1000- // `ty::Value` has a reasonable pretty-printing implementation.
1001- let value = ty:: Value { ty, valtree : value } ;
997+ if let PatRangeBoundary :: Finite ( value) = & self . lo {
1002998 write ! ( f, "{value}" ) ?;
1003999 }
1004- if let & PatRangeBoundary :: Finite ( ty, value) = & self . hi {
1005- let value = ty:: Value { ty, valtree : value } ;
1000+ if let PatRangeBoundary :: Finite ( value) = & self . hi {
10061001 write ! ( f, "{}" , self . end) ?;
10071002 write ! ( f, "{value}" ) ?;
10081003 } else {
@@ -1017,7 +1012,7 @@ impl<'tcx> fmt::Display for PatRange<'tcx> {
10171012/// If present, the const must be of a numeric type.
10181013#[ derive( Copy , Clone , Debug , PartialEq , HashStable , TypeVisitable ) ]
10191014pub enum PatRangeBoundary < ' tcx > {
1020- Finite ( Ty < ' tcx > , ty:: ValTree < ' tcx > ) ,
1015+ Finite ( ty:: Value < ' tcx > ) ,
10211016 NegInfinity ,
10221017 PosInfinity ,
10231018}
@@ -1028,15 +1023,15 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10281023 matches ! ( self , Self :: Finite ( ..) )
10291024 }
10301025 #[ inline]
1031- pub fn as_finite ( self ) -> Option < ty:: ValTree < ' tcx > > {
1026+ pub fn as_finite ( self ) -> Option < ty:: Value < ' tcx > > {
10321027 match self {
1033- Self :: Finite ( _ty , value) => Some ( value) ,
1028+ Self :: Finite ( value) => Some ( value) ,
10341029 Self :: NegInfinity | Self :: PosInfinity => None ,
10351030 }
10361031 }
10371032 pub fn eval_bits ( self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> u128 {
10381033 match self {
1039- Self :: Finite ( _ty , value) => value. unwrap_leaf ( ) . to_bits_unchecked ( ) ,
1034+ Self :: Finite ( value) => value. try_to_scalar_int ( ) . unwrap ( ) . to_bits_unchecked ( ) ,
10401035 Self :: NegInfinity => {
10411036 // Unwrap is ok because the type is known to be numeric.
10421037 ty. numeric_min_and_max_as_bits ( tcx) . unwrap ( ) . 0
@@ -1063,9 +1058,7 @@ impl<'tcx> PatRangeBoundary<'tcx> {
10631058 // we can do scalar comparisons. E.g. `unicode-normalization` has
10641059 // many ranges such as '\u{037A}'..='\u{037F}', and chars can be compared
10651060 // in this way.
1066- ( Finite ( _, a) , Finite ( _, b) )
1067- if matches ! ( ty. kind( ) , ty:: Int ( _) | ty:: Uint ( _) | ty:: Char ) =>
1068- {
1061+ ( Finite ( a) , Finite ( b) ) if matches ! ( ty. kind( ) , ty:: Int ( _) | ty:: Uint ( _) | ty:: Char ) => {
10691062 if let ( Some ( a) , Some ( b) ) = ( a. try_to_scalar_int ( ) , b. try_to_scalar_int ( ) ) {
10701063 let sz = ty. primitive_size ( tcx) ;
10711064 let cmp = match ty. kind ( ) {
0 commit comments