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