rust: pin-init: allow `Zeroable` derive macro to also be applied to unions
authorBenno Lossin <benno.lossin@proton.me>
Mon, 21 Apr 2025 22:18:41 +0000 (22:18 +0000)
committerBenno Lossin <benno.lossin@proton.me>
Thu, 1 May 2025 16:15:12 +0000 (18:15 +0200)
commita313d41a2b515bbb76d56df490b731ff6d64e571
tree90237af12938ddadd641be69df05ede96fb3c84a
parent983d13fc2cf12f0a753700d48be7d04155a1272c
rust: pin-init: allow `Zeroable` derive macro to also be applied to unions

Enabling the same behavior for unions as for structs is correct, but
could be relaxed: the valid bit patterns for unions are the union of all
valid bit patterns of their fields. So for a union to implement
`Zeroable`, only a single field needs to implement `Zeroable`. This can
be a future improvement, as it is currently only needed for unions where
all fields implement `Zeroable`.

There is no danger for mis-parsing with the two optional tokens (ie
neither one or both tokens are parsed), as the compiler will already
have rejected that before giving it as the input to the derive macro.

Link: https://github.com/Rust-for-Linux/pin-init/pull/42/commits/5927b497ce522d82f6c082d5ba9235df57bfdb32
Signed-off-by: Benno Lossin <benno.lossin@proton.me>
rust/pin-init/src/macros.rs