@@ -93,7 +93,7 @@ impl Parse for Newtype {
93
93
}
94
94
impl <E : :: rustc_serialize:: Encoder > :: rustc_serialize:: Encodable <E > for #name {
95
95
fn encode( & self , e: & mut E ) {
96
- e. emit_u32( self . private ) ;
96
+ e. emit_u32( self . as_u32 ( ) ) ;
97
97
}
98
98
}
99
99
}
@@ -103,11 +103,16 @@ impl Parse for Newtype {
103
103
104
104
if ord {
105
105
derive_paths. push ( parse_quote ! ( Ord ) ) ;
106
- derive_paths. push ( parse_quote ! ( PartialOrd ) ) ;
107
106
}
108
107
109
108
let step = if ord {
110
109
quote ! {
110
+ impl :: std:: cmp:: PartialOrd for #name {
111
+ fn partial_cmp( & self , other: & Self ) -> Option <:: std:: cmp:: Ordering > {
112
+ self . as_u32( ) . partial_cmp( & other. as_u32( ) )
113
+ }
114
+ }
115
+
111
116
impl :: std:: iter:: Step for #name {
112
117
#[ inline]
113
118
fn steps_between( start: & Self , end: & Self ) -> Option <usize > {
@@ -150,7 +155,7 @@ impl Parse for Newtype {
150
155
#[ inline]
151
156
fn eq( l: & Option <Self >, r: & Option <Self >) -> bool {
152
157
if #max_val < u32 :: MAX {
153
- l. map( |i| i. private ) . unwrap_or( #max_val+1 ) == r. map( |i| i. private ) . unwrap_or( #max_val+1 )
158
+ l. map( |i| i. as_u32 ( ) ) . unwrap_or( #max_val+1 ) == r. map( |i| i. as_u32 ( ) ) . unwrap_or( #max_val+1 )
154
159
} else {
155
160
match ( l, r) {
156
161
( Some ( l) , Some ( r) ) => r == l,
@@ -170,13 +175,21 @@ impl Parse for Newtype {
170
175
171
176
Ok ( Self ( quote ! {
172
177
#( #attrs) *
173
- #[ derive( Clone , Copy , PartialEq , Eq , Hash , #( #derive_paths) , * ) ]
178
+ #[ derive( Clone , Copy , Eq , Hash , #( #derive_paths) , * ) ]
174
179
#[ rustc_layout_scalar_valid_range_end( #max) ]
175
180
#[ rustc_pass_by_value]
176
181
#vis struct #name {
177
182
private: u32 ,
178
183
}
179
184
185
+ impl :: std:: cmp:: PartialEq for #name {
186
+ fn eq( & self , other: & Self ) -> bool {
187
+ self . as_u32( ) == other. as_u32( )
188
+ }
189
+ }
190
+
191
+ impl :: std:: marker:: StructuralPartialEq for #name { }
192
+
180
193
#( #consts) *
181
194
182
195
impl #name {
@@ -224,7 +237,7 @@ impl Parse for Newtype {
224
237
/// Prefer using `from_u32`.
225
238
#[ inline]
226
239
#vis const unsafe fn from_u32_unchecked( value: u32 ) -> Self {
227
- Self { private: value }
240
+ Self { private: value as _ }
228
241
}
229
242
230
243
/// Extracts the value of this index as a `usize`.
@@ -236,7 +249,7 @@ impl Parse for Newtype {
236
249
/// Extracts the value of this index as a `u32`.
237
250
#[ inline]
238
251
#vis const fn as_u32( self ) -> u32 {
239
- self . private
252
+ self . private as u32
240
253
}
241
254
242
255
/// Extracts the value of this index as a `usize`.
0 commit comments