Re: [PATCH v3 06/15] rust: pin-init: rewrite the `#[pinned_drop]` attribute macro using `syn`

From: Gary Guo

Date: Wed Jan 14 2026 - 13:34:57 EST


On Wed Jan 14, 2026 at 6:18 PM GMT, Benno Lossin wrote:
> 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@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
> * improved error span
> ---
> rust/pin-init/internal/src/lib.rs | 4 +-
> rust/pin-init/internal/src/pinned_drop.rs | 86 +++++++++++++----------
> rust/pin-init/src/macros.rs | 28 --------
> 3 files changed, 52 insertions(+), 66 deletions(-)