]> git.ipfire.org Git - thirdparty/linux.git/commit
rust: pin-init: rewrite `derive(Zeroable)` and `derive(MaybeZeroable)` using `syn`
authorBenno Lossin <lossin@kernel.org>
Fri, 16 Jan 2026 10:54:20 +0000 (11:54 +0100)
committerBenno Lossin <lossin@kernel.org>
Sat, 17 Jan 2026 09:51:42 +0000 (10:51 +0100)
commit50426bde1577d17e61362bd199d487dbeb159110
tree6e1137e2d86256727110ecacf7fd2366ae4db725
parent26bd9402389eaebed086755afb03453dcae6617a
rust: pin-init: rewrite `derive(Zeroable)` and `derive(MaybeZeroable)` using `syn`

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@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Benno Lossin <lossin@kernel.org>
rust/pin-init/internal/src/diagnostics.rs
rust/pin-init/internal/src/lib.rs
rust/pin-init/internal/src/zeroable.rs
rust/pin-init/src/macros.rs