Skip to content

Commit

Permalink
hash: Distinguish field name from our local variable name
Browse files Browse the repository at this point in the history
Fixes the analogous bug to #14 with fields called `state`.
  • Loading branch information
ijackson committed Jan 8, 2024
1 parent 1c091e9 commit dcad41f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/trait_handlers/hash/hash_enum.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use quote::quote;
use quote::{format_ident, quote};
use syn::{Data, DeriveInput, Fields, Ident, Meta, Path, Type};

use super::{
Expand Down Expand Up @@ -61,22 +61,23 @@ impl TraitHandler for HashEnumHandler {
}
.build_from_attributes(&field.attrs, traits)?;

let field_name = field.ident.as_ref().unwrap();
let field_name_real = field.ident.as_ref().unwrap();
let field_name_var = format_ident!("v_{}", field_name_real);

if field_attribute.ignore {
pattern_token_stream.extend(quote!(#field_name: _,));
pattern_token_stream.extend(quote!(#field_name_real: _,));

continue;
}

pattern_token_stream.extend(quote!(#field_name,));
pattern_token_stream.extend(quote!(#field_name_real: #field_name_var,));

let hash = field_attribute.method.as_ref().unwrap_or_else(|| {
hash_types.push(&field.ty);
&built_in_hash
});

block_token_stream.extend(quote!( #hash(#field_name, state); ));
block_token_stream.extend(quote!( #hash(#field_name_var, state); ));
}

arms_token_stream.extend(quote! {
Expand Down

0 comments on commit dcad41f

Please sign in to comment.