@@ -93,7 +93,7 @@ impl Parse for Newtype {
9393 }
9494 impl <E : :: rustc_serialize:: Encoder > :: rustc_serialize:: Encodable <E > for #name {
9595 fn encode( & self , e: & mut E ) {
96- e. emit_u32( self . private ) ;
96+ e. emit_u32( self . as_u32 ( ) ) ;
9797 }
9898 }
9999 }
@@ -103,11 +103,16 @@ impl Parse for Newtype {
103103
104104 if ord {
105105 derive_paths. push ( parse_quote ! ( Ord ) ) ;
106- derive_paths. push ( parse_quote ! ( PartialOrd ) ) ;
107106 }
108107
109108 let step = if ord {
110109 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+
111116 impl :: std:: iter:: Step for #name {
112117 #[ inline]
113118 fn steps_between( start: & Self , end: & Self ) -> Option <usize > {
@@ -150,7 +155,7 @@ impl Parse for Newtype {
150155 #[ inline]
151156 fn eq( l: & Option <Self >, r: & Option <Self >) -> bool {
152157 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 )
154159 } else {
155160 match ( l, r) {
156161 ( Some ( l) , Some ( r) ) => r == l,
@@ -170,13 +175,21 @@ impl Parse for Newtype {
170175
171176 Ok ( Self ( quote ! {
172177 #( #attrs) *
173- #[ derive( Clone , Copy , PartialEq , Eq , Hash , #( #derive_paths) , * ) ]
178+ #[ derive( Clone , Copy , Eq , Hash , #( #derive_paths) , * ) ]
174179 #[ rustc_layout_scalar_valid_range_end( #max) ]
175180 #[ rustc_pass_by_value]
176181 #vis struct #name {
177182 private: u32 ,
178183 }
179184
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+
180193 #( #consts) *
181194
182195 impl #name {
@@ -224,7 +237,7 @@ impl Parse for Newtype {
224237 /// Prefer using `from_u32`.
225238 #[ inline]
226239 #vis const unsafe fn from_u32_unchecked( value: u32 ) -> Self {
227- Self { private: value }
240+ Self { private: value as _ }
228241 }
229242
230243 /// Extracts the value of this index as a `usize`.
@@ -236,7 +249,7 @@ impl Parse for Newtype {
236249 /// Extracts the value of this index as a `u32`.
237250 #[ inline]
238251 #vis const fn as_u32( self ) -> u32 {
239- self . private
252+ self . private as u32
240253 }
241254
242255 /// Extracts the value of this index as a `usize`.
0 commit comments