Re: [PATCH v4 07/15] rust: pin-init: rewrite `#[pin_data]` using `syn`

From: Gary Guo

Date: Fri Jan 16 2026 - 06:41:03 EST


On Fri Jan 16, 2026 at 10:54 AM GMT, Benno Lossin wrote:
> Rewrite the attribute macro `#[pin_data]` using `syn`. No functional
> changes intended aside from improved error messages on syntactic and
> semantical errors. For example if one forgets a comma at the end of a
> field:
>
> #[pin_data]
> struct Foo {
> a: Box<Foo>
> b: Box<Foo>
> }
>
> The declarative macro reports the following errors:
>
> error: expected `,`, or `}`, found `b`
> --> tests/ui/compile-fail/pin_data/missing_comma.rs:5:16
> |
> 5 | a: Box<Foo>
> | ^ help: try adding a comma: `,`
>
> error: recursion limit reached while expanding `$crate::__pin_data!`
> --> tests/ui/compile-fail/pin_data/missing_comma.rs:3:1
> |
> 3 | #[pin_data]
> | ^^^^^^^^^^^
> |
> = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`$CRATE`)
> = note: this error originates in the macro `$crate::__pin_data` which comes from the expansion of the attribute macro `pin_data` (in Nightly builds, run with -Z macro-backtrace for more info)
>
> The new `syn` version reports:
>
> error: expected `,`, or `}`, found `b`
> --> tests/ui/compile-fail/pin_data/missing_comma.rs:5:16
> |
> 5 | a: Box<Foo>
> | ^ help: try adding a comma: `,`
>
> error: expected `,`
> --> tests/ui/compile-fail/pin_data/missing_comma.rs:6:5
> |
> 6 | b: Box<Foo>
> | ^
>
> Tested-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
> Signed-off-by: Benno Lossin <lossin@xxxxxxxxxx>

Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>

> ---
> Changes in v4:
> * improve parsing
> * consolidate generics handling
> * improve handling of `#[pin]` attributes
> Changes in v3:
> * use DiagCtxt error handling
> Changes in v2:
> * improved error handling
> * fix clippy warnings
> * fix typos and variable names
> * collect the information about the pinned/not pinned fields only once
> at the beginning
> ---
> rust/pin-init/internal/src/helpers.rs | 149 ------
> rust/pin-init/internal/src/lib.rs | 7 +-
> rust/pin-init/internal/src/pin_data.rs | 611 ++++++++++++++++++++-----
> rust/pin-init/src/macros.rs | 574 -----------------------
> 4 files changed, 503 insertions(+), 838 deletions(-)
> delete mode 100644 rust/pin-init/internal/src/helpers.rs