@@ -147,7 +147,7 @@ use darling::{FromDeriveInput, FromMeta};
147147use proc_macro:: TokenStream ;
148148use quote:: quote;
149149use std:: convert:: TryInto ;
150- use syn:: { parse_macro_input, DataEnum , DataStruct , DeriveInput , Ident } ;
150+ use syn:: { parse_macro_input, DataEnum , DataStruct , DeriveInput , Ident , Index } ;
151151
152152/// The highest possible union selector value (higher values are reserved for backwards compatible
153153/// extensions).
@@ -442,11 +442,15 @@ fn ssz_encode_derive_struct_transparent(
442442 ) ;
443443 }
444444
445- let ( ty, ident, _field_opts) = ssz_fields
445+ let ( index , ( ty, ident, _field_opts) ) = ssz_fields
446446 . iter ( )
447- . find ( |( _, _, field_opts) | !field_opts. skip_deserializing )
447+ . enumerate ( )
448+ . find ( |( _, ( _, _, field_opts) ) | !field_opts. skip_deserializing )
448449 . expect ( "\" transparent\" struct must have at least one non-skipped field" ) ;
449450
451+ // Remove the `_usize` suffix from the value to avoid a compiler warning.
452+ let index = Index :: from ( index) ;
453+
450454 let output = if let Some ( field_name) = ident {
451455 quote ! {
452456 impl #impl_generics ssz:: Encode for #name #ty_generics #where_clause {
@@ -479,11 +483,11 @@ fn ssz_encode_derive_struct_transparent(
479483 }
480484
481485 fn ssz_bytes_len( & self ) -> usize {
482- self . 0 . ssz_bytes_len( )
486+ self . #index . ssz_bytes_len( )
483487 }
484488
485489 fn ssz_append( & self , buf: & mut Vec <u8 >) {
486- self . 0 . ssz_append( buf)
490+ self . #index . ssz_append( buf)
487491 }
488492 }
489493 }
0 commit comments