Skip to content

Commit

Permalink
Allow padding fields to have duplicate names
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorygaines committed Dec 16, 2024
1 parent f3b5fb1 commit 2e20f15
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions bitfields/tests/lib_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,18 @@ mod tests {
t.compile_fail("tests/compile_error_cases/bitfield_field_duplicate_name.rs");
}

#[test]
fn bitfield_field_duplicate_padding_name() {
#[bitfield(u16)]
pub struct Bitfield {
a: u8,
#[bits(4)]
__: u8,
#[bits(4)]
__: u8,
}
}

#[test]
fn bitfield_field_padding() {
#[bitfield(u64)]
Expand Down
4 changes: 3 additions & 1 deletion bitfields_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,9 @@ fn check_bitfield_names_unique(fields: &[BitfieldField]) -> syn::Result<()> {
),
));
}
field_names.push(field.name.clone());
if !field.padding {
field_names.push(field.name.clone());
}
}

Ok(())
Expand Down

0 comments on commit 2e20f15

Please sign in to comment.