@@ -11,13 +11,16 @@ use syn::{
1111 TraitBoundModifier , Type , TypeParamBound , TypePath , WhereClause , WherePredicate ,
1212} ;
1313
14- use crate :: { util, Error , Item , Skip , SkipGroup , Trait , TraitImpl , DERIVE_WHERE } ;
14+ use crate :: { util, Error , Incomparable , Item , Skip , SkipGroup , Trait , TraitImpl , DERIVE_WHERE } ;
1515
1616/// Attributes on item.
1717#[ derive( Default ) ]
1818pub struct ItemAttr {
1919 /// [`Trait`]s to skip all fields for.
2020 pub skip_inner : Skip ,
21+ /// Comparing item will yield `false` for [`PartialEq`] and [`None`] for
22+ /// [`PartialOrd`].
23+ pub incomparable : Incomparable ,
2124 /// [`DeriveWhere`]s on this item.
2225 pub derive_wheres : Vec < DeriveWhere > ,
2326}
@@ -27,6 +30,7 @@ impl ItemAttr {
2730 pub fn from_attrs ( span : Span , data : & Data , attrs : & [ Attribute ] ) -> Result < Self > {
2831 let mut self_ = ItemAttr :: default ( ) ;
2932 let mut skip_inners = Vec :: new ( ) ;
33+ let mut incomparables = Vec :: new ( ) ;
3034
3135 for attr in attrs {
3236 if attr. path . is_ident ( DERIVE_WHERE ) {
@@ -52,6 +56,9 @@ impl ItemAttr {
5256 // Don't parse `Skip` yet, because it needs access to all
5357 // `DeriveWhere`s.
5458 skip_inners. push ( meta) ;
59+ } else if meta. path ( ) . is_ident ( Incomparable :: INCOMPARABLE ) {
60+ // Needs to be parsed after all traits are known.
61+ incomparables. push ( meta)
5562 } else if meta. path ( ) . is_ident ( "crate" ) {
5663 // Do nothing, we checked this before
5764 // already.
@@ -119,14 +126,20 @@ impl ItemAttr {
119126 }
120127 }
121128
122- // Delayed parsing of `skip_inner` to get access to all traits to be
123- // implemented.
129+ // Delayed parsing of `skip_inner` and `incomparable` to get access to all
130+ // traits to be implemented.
124131 for meta in skip_inners {
125132 self_
126133 . skip_inner
127134 . add_attribute ( & self_. derive_wheres , None , & meta) ?;
128135 }
129136
137+ for meta in incomparables {
138+ self_
139+ . incomparable
140+ . add_attribute ( & meta, & self_. derive_wheres ) ?;
141+ }
142+
130143 Ok ( self_)
131144 }
132145}
0 commit comments