@@ -579,6 +579,12 @@ struct ExpandData {
579579 min_data_len : usize ,
580580 trait_ : Ident ,
581581 selectors : Vec < ExprArray < u8 > > ,
582+ /// Whether the builtin `#[sol(all_derives)]` traits can be derived on the
583+ /// generated enum. Computed from the underlying items' parameter types,
584+ /// because the variant type names may be synthetic (overloaded items get
585+ /// `_N` suffixes, call variants use `*Call` structs) and thus not
586+ /// resolvable as items.
587+ can_derive_builtin : bool ,
582588}
583589
584590impl ExpandData {
@@ -645,6 +651,9 @@ impl ToExpand<'_> {
645651 . unwrap ( ) ,
646652 trait_ : format_ident ! ( "SolCall" ) ,
647653 selectors : functions. iter ( ) . map ( |f| cx. function_selector ( f) ) . collect ( ) ,
654+ can_derive_builtin : functions
655+ . iter ( )
656+ . all ( |f| f. parameters . types ( ) . all ( |ty| cx. can_derive_builtin_traits ( ty) ) ) ,
648657 }
649658 }
650659
@@ -659,6 +668,9 @@ impl ToExpand<'_> {
659668 . unwrap ( ) ,
660669 trait_ : format_ident ! ( "SolError" ) ,
661670 selectors : errors. iter ( ) . map ( |e| cx. error_selector ( e) ) . collect ( ) ,
671+ can_derive_builtin : errors. iter ( ) . all ( |& error| {
672+ error. parameters . types ( ) . all ( |ty| cx. can_derive_builtin_traits ( ty) )
673+ } ) ,
662674 } ,
663675
664676 Self :: Events ( events) => {
@@ -676,6 +688,9 @@ impl ToExpand<'_> {
676688 . unwrap ( ) ,
677689 trait_ : format_ident ! ( "SolEvent" ) ,
678690 selectors : events. iter ( ) . map ( |e| cx. event_selector ( e) ) . collect ( ) ,
691+ can_derive_builtin : events. iter ( ) . all ( |& event| {
692+ event. parameters . iter ( ) . all ( |p| cx. can_derive_builtin_traits ( & p. ty ) )
693+ } ) ,
679694 }
680695 }
681696 }
@@ -918,7 +933,7 @@ impl CallLikeExpander<'_> {
918933 assert ! ( selectors. iter( ) . all( |s| s. array. len( ) == selector_len) ) ;
919934 let selector_type = quote ! ( [ u8 ; #selector_len] ) ;
920935
921- self . cx . type_derives ( & mut attrs, types . iter ( ) . cloned ( ) . map ( ast :: Type :: custom ) , false ) ;
936+ self . cx . enum_derives ( & mut attrs, data . can_derive_builtin ) ;
922937 let trait_ = & data. trait_ ;
923938
924939 let mut tokens = quote ! {
0 commit comments