Skip to content

internal: add tuple struct support in pin_data and pin_init!#113

Open
mqqz wants to merge 3 commits intoRust-for-Linux:mainfrom
mqqz:add_tuple_structs
Open

internal: add tuple struct support in pin_data and pin_init!#113
mqqz wants to merge 3 commits intoRust-for-Linux:mainfrom
mqqz:add_tuple_structs

Conversation

@mqqz
Copy link

@mqqz mqqz commented Feb 28, 2026

Extend pin_data and pin_init! to support tuple struct syntax.

pin_data (internal/src/pin_data.rs):

  • add tuple-field handling via a refactored FieldInfo struct
  • generate projections and pin-data accessors for unnamed members

pin_init! (internal/src/init.rs):

  • parse initialiser keys as syn::Member (named or tuple index)
  • extend parser to support both:
    • tuple-like syntax e.g. Foo(a, <- b, c)
    • and brace syntax e.g. Foo{0 : a, 1 <- b, 2: c}
    • Couldn't decide on appropriate syntax, I'm not sure if keeping both is a good idea

Testing:

  • tests/tuple_struct.rs
  • tests/ui/compile-fail/tuple_{duplicate,invalid,missing}_field.rs
  • tests/ui/compile-fail/tuple_shorthand.rs
  • tests/ui/expand/pin_{data,init}

Note that currently for tuple struct internal fields identifiers like _0 (for the first index) which clippy doesn't like. I'm not sure whether it's better to change naming or add #[allow(clippy::just_underscores_and_digits)] (I don't want to go through the effort of spamming clippy and changing all expanded tests just yet).

Closes: #85

@mqqz mqqz marked this pull request as draft February 28, 2026 18:14
@mqqz mqqz force-pushed the add_tuple_structs branch 4 times, most recently from b3f93db to cd3f0a3 Compare March 2, 2026 21:32
mqqz added 2 commits March 3, 2026 00:33
Introduce `FieldInfo` struct to encapsulate field and other relevant
data (e.g. pinned and member name) to abstract over named/unnamed
fields.

Also, generate projections and pin-data accessors for unnamed
members.

Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
Refactor to parse initialiser keys as `Member` (named or tuple index).

Additionally, extend init parser to support both tuple-like init
constructor e.g. `Foo(a, <- b, c)` and brace syntax e.g.
`Foo{0 : a, 1 <- b, 2: c}`.

Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
@mqqz mqqz force-pushed the add_tuple_structs branch from cd3f0a3 to 78043e4 Compare March 2, 2026 21:33
@mqqz mqqz marked this pull request as ready for review March 2, 2026 21:55
Tests include:
  - `tests/tuple_struct.rs`
  - `tests/ui/compile-fail/tuple_{duplicate,invalid,missing}_field.rs`
  - `tests/ui/compile-fail/tuple_shorthand.rs`
  - `tests/ui/expand/pin_{data,init}`

Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
@mqqz mqqz force-pushed the add_tuple_structs branch from f58c415 to 757cb2e Compare March 2, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Support for initializing tuple-structs

1 participant