@@ -840,10 +840,7 @@ pub enum PatKind<'tcx> {
840
840
/// much simpler.
841
841
/// * `String`, if `string_deref_patterns` is enabled.
842
842
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 > ,
847
844
} ,
848
845
849
846
/// Pattern obtained by converting a constant (inline or named) to its pattern
@@ -935,17 +932,17 @@ impl<'tcx> PatRange<'tcx> {
935
932
// Also, for performance, it's important to only do the second `try_to_bits` if necessary.
936
933
let lo_is_min = match self . lo {
937
934
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;
940
937
lo <= min
941
938
}
942
939
PatRangeBoundary :: PosInfinity => false ,
943
940
} ;
944
941
if lo_is_min {
945
942
let hi_is_max = match self . hi {
946
943
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;
949
946
hi > max || hi == max && self . end == RangeEnd :: Included
950
947
}
951
948
PatRangeBoundary :: PosInfinity => true ,
@@ -958,10 +955,11 @@ impl<'tcx> PatRange<'tcx> {
958
955
}
959
956
960
957
#[ 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 > {
962
959
use Ordering :: * ;
960
+ debug_assert_eq ! ( self . ty, value. ty) ;
963
961
let ty = self . ty ;
964
- let value = PatRangeBoundary :: Finite ( ty , value) ;
962
+ let value = PatRangeBoundary :: Finite ( value) ;
965
963
// For performance, it's important to only do the second comparison if necessary.
966
964
Some (
967
965
match self . lo . compare_with ( value, ty, tcx) ? {
@@ -996,13 +994,10 @@ impl<'tcx> PatRange<'tcx> {
996
994
997
995
impl < ' tcx > fmt:: Display for PatRange < ' tcx > {
998
996
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 {
1002
998
write ! ( f, "{value}" ) ?;
1003
999
}
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 {
1006
1001
write ! ( f, "{}" , self . end) ?;
1007
1002
write ! ( f, "{value}" ) ?;
1008
1003
} else {
@@ -1017,7 +1012,7 @@ impl<'tcx> fmt::Display for PatRange<'tcx> {
1017
1012
/// If present, the const must be of a numeric type.
1018
1013
#[ derive( Copy , Clone , Debug , PartialEq , HashStable , TypeVisitable ) ]
1019
1014
pub enum PatRangeBoundary < ' tcx > {
1020
- Finite ( Ty < ' tcx > , ty:: ValTree < ' tcx > ) ,
1015
+ Finite ( ty:: Value < ' tcx > ) ,
1021
1016
NegInfinity ,
1022
1017
PosInfinity ,
1023
1018
}
@@ -1028,15 +1023,15 @@ impl<'tcx> PatRangeBoundary<'tcx> {
1028
1023
matches ! ( self , Self :: Finite ( ..) )
1029
1024
}
1030
1025
#[ inline]
1031
- pub fn as_finite ( self ) -> Option < ty:: ValTree < ' tcx > > {
1026
+ pub fn as_finite ( self ) -> Option < ty:: Value < ' tcx > > {
1032
1027
match self {
1033
- Self :: Finite ( _ty , value) => Some ( value) ,
1028
+ Self :: Finite ( value) => Some ( value) ,
1034
1029
Self :: NegInfinity | Self :: PosInfinity => None ,
1035
1030
}
1036
1031
}
1037
1032
pub fn eval_bits ( self , ty : Ty < ' tcx > , tcx : TyCtxt < ' tcx > ) -> u128 {
1038
1033
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 ( ) ,
1040
1035
Self :: NegInfinity => {
1041
1036
// Unwrap is ok because the type is known to be numeric.
1042
1037
ty. numeric_min_and_max_as_bits ( tcx) . unwrap ( ) . 0
@@ -1063,9 +1058,7 @@ impl<'tcx> PatRangeBoundary<'tcx> {
1063
1058
// we can do scalar comparisons. E.g. `unicode-normalization` has
1064
1059
// many ranges such as '\u{037A}'..='\u{037F}', and chars can be compared
1065
1060
// 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 ) => {
1069
1062
if let ( Some ( a) , Some ( b) ) = ( a. try_to_scalar_int ( ) , b. try_to_scalar_int ( ) ) {
1070
1063
let sz = ty. primitive_size ( tcx) ;
1071
1064
let cmp = match ty. kind ( ) {
0 commit comments