Re: [PATCH v2] rust: bitfield: require integer storage

From: Gary Guo

Date: Tue Sep 22 2026 - 10:13:35 EST


On Tue Sep 22, 2026 at 2:53 PM BST, Alexandre Courbot wrote:
>>
>> - // SAFETY: `$storage` is `Zeroable` and `$name` is transparent.
>> - unsafe impl ::pin_init::Zeroable for $name {}
>> + // SAFETY:
>> + // - `$storage: Integer` is sealed to primitive integer types, for which the all-zero bit
>> + // pattern is valid.
>> + // - `$name` is `repr(transparent)` over `$storage`.
>> + unsafe impl ::pin_init::Zeroable for $name
>> + where $storage: ::kernel::num::Integer
>> + {}
>
> While I guess that would somehow work, I think the proper place to do
> this is the struct definition, i.e:
>
> $vis struct $name
> where
> $storage: $crate::num::Integer,
> {
> inner: $storage,
> }
>
> This makes the error message also more explicit about what the problem
> is (a bitfield requires an `Integer`, not merely the ability to
> initialize it to zero).

Agreed.

Best,
Gary