Re: [PATCH v3 05/15] rust: pin-init: rewrite `derive(Zeroable)` and `derive(MaybeZeroable)` using `syn`

From: Gary Guo

Date: Wed Jan 14 2026 - 13:29:10 EST


On Wed Jan 14, 2026 at 6:18 PM GMT, Benno Lossin wrote:
> Rewrite the two derive macros for `Zeroable` using `syn`. One positive
> side effect of this change is that tuple structs are now supported by
> them. Additionally, syntax errors and the error emitted when trying to
> use one of the derive macros on an `enum` are improved. Otherwise no
> functional changes intended.
>
> For example:
>
> #[derive(Zeroable)]
> enum Num {
> A(u32),
> B(i32),
> }
>
> Produced this error before this commit:
>
> error: no rules expected keyword `enum`
> --> tests/ui/compile-fail/zeroable/enum.rs:5:1
> |
> 5 | enum Num {
> | ^^^^ no rules expected this token in macro call
> |
> note: while trying to match keyword `struct`
> --> src/macros.rs
> |
> | $vis:vis struct $name:ident
> | ^^^^^^
>
> Now the error is:
>
> error: cannot derive `Zeroable` for an enum
> --> tests/ui/compile-fail/zeroable/enum.rs:5:1
> |
> 5 | enum Num {
> | ^^^^
>
> error: cannot derive `Zeroable` for an enum
>
> Tested-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
> Signed-off-by: Benno Lossin <lossin@xxxxxxxxxx>

Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>

> ---
> Changes in v3:
> * use DiagCtxt error handling
> Changes in v2:
> * improved error handling
> ---
> rust/pin-init/internal/src/diagnostics.rs | 2 -
> rust/pin-init/internal/src/lib.rs | 9 +-
> rust/pin-init/internal/src/zeroable.rs | 155 ++++++++++------------
> rust/pin-init/src/macros.rs | 124 -----------------
> 4 files changed, 74 insertions(+), 216 deletions(-)