From 5879f84d173e083257a0cafb4969894e18d66ccc Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Thu, 28 May 2020 11:37:40 +1000 Subject: [PATCH] Fix eval order lint in ssz_derive (#1210) --- consensus/ssz_derive/src/lib.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/consensus/ssz_derive/src/lib.rs b/consensus/ssz_derive/src/lib.rs index ae350a1cb..cf3a2399a 100644 --- a/consensus/ssz_derive/src/lib.rs +++ b/consensus/ssz_derive/src/lib.rs @@ -176,6 +176,7 @@ pub fn ssz_decode_derive(input: TokenStream) -> TokenStream { }; let mut register_types = vec![]; + let mut field_names = vec![]; let mut fixed_decodes = vec![]; let mut decodes = vec![]; let mut is_fixed_lens = vec![]; @@ -186,14 +187,18 @@ pub fn ssz_decode_derive(input: TokenStream) -> TokenStream { for field in &struct_data.fields { match &field.ident { Some(ref ident) => { + field_names.push(quote! { + #ident + }); + if should_skip_deserializing(field) { // Field should not be deserialized; use a `Default` impl to instantiate. decodes.push(quote! { - #ident: <_>::default() + let #ident = <_>::default(); }); fixed_decodes.push(quote! { - #ident: <_>::default() + let #ident = <_>::default(); }); } else { let ty = &field.ty; @@ -203,11 +208,11 @@ pub fn ssz_decode_derive(input: TokenStream) -> TokenStream { }); decodes.push(quote! { - #ident: decoder.decode_next()? + let #ident = decoder.decode_next()?; }); fixed_decodes.push(quote! { - #ident: decode_field!(#ty) + let #ident = decode_field!(#ty); }); is_fixed_lens.push(quote! { @@ -269,9 +274,13 @@ pub fn ssz_decode_derive(input: TokenStream) -> TokenStream { }}; } + #( + #fixed_decodes + )* + Ok(Self { #( - #fixed_decodes, + #field_names, )* }) } else { @@ -283,9 +292,14 @@ pub fn ssz_decode_derive(input: TokenStream) -> TokenStream { let mut decoder = builder.build()?; + #( + #decodes + )* + + Ok(Self { #( - #decodes, + #field_names, )* }) }