Use __BindgenBitfieldUnit::new() to build the bitfield. Since the generated type implements PartialEq, compare the bitfields directly in test_family_flags_bitfield(). Signed-off-by: Thorsten Blum --- test_family_flags_bitfield() still passes. rust/kernel/net/netlink.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/rust/kernel/net/netlink.rs b/rust/kernel/net/netlink.rs index 2f8733a694a9..d0c79a254f12 100644 --- a/rust/kernel/net/netlink.rs +++ b/rust/kernel/net/netlink.rs @@ -180,8 +180,7 @@ impl FamilyFlags { } // Convert from little endian to the target's endianness. bits = u8::from_le(bits); - // SAFETY: This bitfield is represented as an u8. - unsafe { core::mem::transmute::>(bits) } + bindings::__BindgenBitfieldUnit::new([bits]) } } @@ -335,11 +334,7 @@ fn test_family_flags_bitfield() { } .into_bitfield(); - // SAFETY: The bit field is stored as u8. - let b_val: u8 = unsafe { core::mem::transmute(b_fam._bitfield_1) }; - // SAFETY: The bit field is stored as u8. - let c_val: u8 = unsafe { core::mem::transmute(c_bitfield) }; - assert_eq!(b_val, c_val); + assert_eq!(b_fam._bitfield_1, c_bitfield); } } }