Re: [PATCH] rust: bitfield: require Zeroable storage for Zeroable impl

From: Yilin Chen

Date: Mon Sep 21 2026 - 02:32:59 EST


Hi Gary,

Resending my reply for visibility on the mailing list.

You are right that a bitfield with at least one field generates a use of
`Bounded<$storage, ...>`, which requires the storage type to implement
`Integer`. However, `bitfield!` also accepts an empty field list. In that
case, no `Bounded` use is generated, so the `Integer` requirement is
absent, while the macro still generates the unconditional `Zeroable`
implementation.

For example:

use core::num::NonZeroU32;
use pin_init::Zeroable;

bitfield! {
struct Bad(NonZeroU32) {}
}

fn check_bad_zeroable() {
let _: Bad = <Bad as Zeroable>::zeroed();
}

This currently compiles. Since the all-zero bit pattern is invalid for
`NonZeroU32`, the generated `Zeroable` implementation is unsound. This is
why I think the explicit `$storage: Zeroable` bound is necessary.

Best regards,
Yilin