@@ -48,27 +48,27 @@ pub enum Constant {
48
48
impl PartialEq for Constant {
49
49
fn eq ( & self , other : & Self ) -> bool {
50
50
match ( self , other) {
51
- ( & Constant :: Str ( ref ls) , & Constant :: Str ( ref rs) ) => ls == rs,
52
- ( & Constant :: Binary ( ref l) , & Constant :: Binary ( ref r) ) => l == r,
53
- ( & Constant :: Char ( l) , & Constant :: Char ( r) ) => l == r,
54
- ( & Constant :: Int ( l) , & Constant :: Int ( r) ) => l == r,
55
- ( & Constant :: F64 ( l) , & Constant :: F64 ( r) ) => {
51
+ ( & Self :: Str ( ref ls) , & Self :: Str ( ref rs) ) => ls == rs,
52
+ ( & Self :: Binary ( ref l) , & Self :: Binary ( ref r) ) => l == r,
53
+ ( & Self :: Char ( l) , & Self :: Char ( r) ) => l == r,
54
+ ( & Self :: Int ( l) , & Self :: Int ( r) ) => l == r,
55
+ ( & Self :: F64 ( l) , & Self :: F64 ( r) ) => {
56
56
// We want `Fw32 == FwAny` and `FwAny == Fw64`, and by transitivity we must have
57
57
// `Fw32 == Fw64`, so don’t compare them.
58
58
// `to_bits` is required to catch non-matching 0.0, -0.0, and NaNs.
59
59
l. to_bits ( ) == r. to_bits ( )
60
60
} ,
61
- ( & Constant :: F32 ( l) , & Constant :: F32 ( r) ) => {
61
+ ( & Self :: F32 ( l) , & Self :: F32 ( r) ) => {
62
62
// We want `Fw32 == FwAny` and `FwAny == Fw64`, and by transitivity we must have
63
63
// `Fw32 == Fw64`, so don’t compare them.
64
64
// `to_bits` is required to catch non-matching 0.0, -0.0, and NaNs.
65
65
f64:: from ( l) . to_bits ( ) == f64:: from ( r) . to_bits ( )
66
66
} ,
67
- ( & Constant :: Bool ( l) , & Constant :: Bool ( r) ) => l == r,
68
- ( & Constant :: Vec ( ref l) , & Constant :: Vec ( ref r) ) | ( & Constant :: Tuple ( ref l) , & Constant :: Tuple ( ref r) ) => {
67
+ ( & Self :: Bool ( l) , & Self :: Bool ( r) ) => l == r,
68
+ ( & Self :: Vec ( ref l) , & Self :: Vec ( ref r) ) | ( & Self :: Tuple ( ref l) , & Self :: Tuple ( ref r) ) => {
69
69
l == r
70
70
} ,
71
- ( & Constant :: Repeat ( ref lv, ref ls) , & Constant :: Repeat ( ref rv, ref rs) ) => ls == rs && lv == rv,
71
+ ( & Self :: Repeat ( ref lv, ref ls) , & Self :: Repeat ( ref rv, ref rs) ) => ls == rs && lv == rv,
72
72
// TODO: are there inter-type equalities?
73
73
_ => false ,
74
74
}
@@ -82,38 +82,38 @@ impl Hash for Constant {
82
82
{
83
83
std:: mem:: discriminant ( self ) . hash ( state) ;
84
84
match * self {
85
- Constant :: Str ( ref s) => {
85
+ Self :: Str ( ref s) => {
86
86
s. hash ( state) ;
87
87
} ,
88
- Constant :: Binary ( ref b) => {
88
+ Self :: Binary ( ref b) => {
89
89
b. hash ( state) ;
90
90
} ,
91
- Constant :: Char ( c) => {
91
+ Self :: Char ( c) => {
92
92
c. hash ( state) ;
93
93
} ,
94
- Constant :: Int ( i) => {
94
+ Self :: Int ( i) => {
95
95
i. hash ( state) ;
96
96
} ,
97
- Constant :: F32 ( f) => {
97
+ Self :: F32 ( f) => {
98
98
f64:: from ( f) . to_bits ( ) . hash ( state) ;
99
99
} ,
100
- Constant :: F64 ( f) => {
100
+ Self :: F64 ( f) => {
101
101
f. to_bits ( ) . hash ( state) ;
102
102
} ,
103
- Constant :: Bool ( b) => {
103
+ Self :: Bool ( b) => {
104
104
b. hash ( state) ;
105
105
} ,
106
- Constant :: Vec ( ref v) | Constant :: Tuple ( ref v) => {
106
+ Self :: Vec ( ref v) | Self :: Tuple ( ref v) => {
107
107
v. hash ( state) ;
108
108
} ,
109
- Constant :: Repeat ( ref c, l) => {
109
+ Self :: Repeat ( ref c, l) => {
110
110
c. hash ( state) ;
111
111
l. hash ( state) ;
112
112
} ,
113
- Constant :: RawPtr ( u) => {
113
+ Self :: RawPtr ( u) => {
114
114
u. hash ( state) ;
115
115
} ,
116
- Constant :: Err ( ref s) => {
116
+ Self :: Err ( ref s) => {
117
117
s. hash ( state) ;
118
118
} ,
119
119
}
@@ -123,25 +123,25 @@ impl Hash for Constant {
123
123
impl Constant {
124
124
pub fn partial_cmp ( tcx : TyCtxt < ' _ > , cmp_type : Ty < ' _ > , left : & Self , right : & Self ) -> Option < Ordering > {
125
125
match ( left, right) {
126
- ( & Constant :: Str ( ref ls) , & Constant :: Str ( ref rs) ) => Some ( ls. cmp ( rs) ) ,
127
- ( & Constant :: Char ( ref l) , & Constant :: Char ( ref r) ) => Some ( l. cmp ( r) ) ,
128
- ( & Constant :: Int ( l) , & Constant :: Int ( r) ) => {
126
+ ( & Self :: Str ( ref ls) , & Self :: Str ( ref rs) ) => Some ( ls. cmp ( rs) ) ,
127
+ ( & Self :: Char ( ref l) , & Self :: Char ( ref r) ) => Some ( l. cmp ( r) ) ,
128
+ ( & Self :: Int ( l) , & Self :: Int ( r) ) => {
129
129
if let ty:: Int ( int_ty) = cmp_type. sty {
130
130
Some ( sext ( tcx, l, int_ty) . cmp ( & sext ( tcx, r, int_ty) ) )
131
131
} else {
132
132
Some ( l. cmp ( & r) )
133
133
}
134
134
} ,
135
- ( & Constant :: F64 ( l) , & Constant :: F64 ( r) ) => l. partial_cmp ( & r) ,
136
- ( & Constant :: F32 ( l) , & Constant :: F32 ( r) ) => l. partial_cmp ( & r) ,
137
- ( & Constant :: Bool ( ref l) , & Constant :: Bool ( ref r) ) => Some ( l. cmp ( r) ) ,
138
- ( & Constant :: Tuple ( ref l) , & Constant :: Tuple ( ref r) ) | ( & Constant :: Vec ( ref l) , & Constant :: Vec ( ref r) ) => l
135
+ ( & Self :: F64 ( l) , & Self :: F64 ( r) ) => l. partial_cmp ( & r) ,
136
+ ( & Self :: F32 ( l) , & Self :: F32 ( r) ) => l. partial_cmp ( & r) ,
137
+ ( & Self :: Bool ( ref l) , & Self :: Bool ( ref r) ) => Some ( l. cmp ( r) ) ,
138
+ ( & Self :: Tuple ( ref l) , & Self :: Tuple ( ref r) ) | ( & Self :: Vec ( ref l) , & Self :: Vec ( ref r) ) => l
139
139
. iter ( )
140
140
. zip ( r. iter ( ) )
141
141
. map ( |( li, ri) | Self :: partial_cmp ( tcx, cmp_type, li, ri) )
142
142
. find ( |r| r. map_or ( true , |o| o != Ordering :: Equal ) )
143
143
. unwrap_or_else ( || Some ( l. len ( ) . cmp ( & r. len ( ) ) ) ) ,
144
- ( & Constant :: Repeat ( ref lv, ref ls) , & Constant :: Repeat ( ref rv, ref rs) ) => {
144
+ ( & Self :: Repeat ( ref lv, ref ls) , & Self :: Repeat ( ref rv, ref rs) ) => {
145
145
match Self :: partial_cmp ( tcx, cmp_type, lv, rv) {
146
146
Some ( Equal ) => Some ( ls. cmp ( rs) ) ,
147
147
x => x,
0 commit comments