Skip to content

Commit

Permalink
fix bug in generated struct field placement
Browse files Browse the repository at this point in the history
  • Loading branch information
realbigsean committed Jan 31, 2024
1 parent 107b063 commit 748e0a5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pub fn superstruct(args: TokenStream, input: TokenStream) -> TokenStream {
let mut variant_fields =
HashMap::<_, _>::from_iter(variant_names.iter().zip(iter::repeat(vec![])));

for field in item.fields.iter() {
for (field_index, field) in item.fields.iter().enumerate() {
let name = field.ident.clone().expect("named fields only");
let field_opts = field
.attrs
Expand Down Expand Up @@ -246,7 +246,7 @@ pub fn superstruct(args: TokenStream, input: TokenStream) -> TokenStream {
let fields = variant_fields
.get_mut(variant)
.expect("invalid variant name");
*fields.get_mut(0).expect("no fields for variant") = next_variant_field;
*fields.get_mut(field_index).expect("invalid field index") = next_variant_field;
}
} else {
fields.push(FieldData {
Expand Down

0 comments on commit 748e0a5

Please sign in to comment.