]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
rust: pin-init: rewrite the `#[pinned_drop]` attribute macro using `syn`
authorBenno Lossin <lossin@kernel.org>
Fri, 16 Jan 2026 10:54:21 +0000 (11:54 +0100)
committerBenno Lossin <lossin@kernel.org>
Sat, 17 Jan 2026 09:51:42 +0000 (10:51 +0100)
commita92f5fd29257d3bb4c62b81aebca0774e5f5c856
tree3196fb60864391b3505ff0057818d787ccaa9dc2
parent50426bde1577d17e61362bd199d487dbeb159110
rust: pin-init: rewrite the `#[pinned_drop]` attribute macro using `syn`

Rewrite the attribute macro for implementing `PinnedDrop` using `syn`.
Otherwise no functional changes intended aside from improved error
messages on syntactic and semantical errors. For example:

When missing the `drop` function in the implementation, the old error
was:

    error: no rules expected `)`
     --> tests/ui/compile-fail/pinned_drop/no_fn.rs:6:1
      |
    6 | #[pinned_drop]
      | ^^^^^^^^^^^^^^ no rules expected this token in macro call
      |
    note: while trying to match keyword `fn`
     --> src/macros.rs
      |
      |             fn drop($($sig:tt)*) {
      |             ^^
      = note: this error originates in the attribute macro `pinned_drop` (in Nightly builds, run with -Z macro-backtrace for more info)

And the new one is:

    error[E0046]: not all trait items implemented, missing: `drop`
     --> tests/ui/compile-fail/pinned_drop/no_fn.rs:7:1
      |
    7 | impl PinnedDrop for Foo {}
      | ^^^^^^^^^^^^^^^^^^^^^^^ missing `drop` in implementation
      |
      = help: implement the missing item: `fn drop(self: Pin<&mut Self>, _: OnlyCallFromDrop) { todo!() }`

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/lib.rs
rust/pin-init/internal/src/pinned_drop.rs
rust/pin-init/src/macros.rs