Skip to content

internal: add tuple struct support in pin_data and pin_init! (V2)#155

Open
mqqz wants to merge 4 commits into
Rust-for-Linux:mainfrom
mqqz:add_tuple_structs_v2
Open

internal: add tuple struct support in pin_data and pin_init! (V2)#155
mqqz wants to merge 4 commits into
Rust-for-Linux:mainfrom
mqqz:add_tuple_structs_v2

Conversation

@mqqz
Copy link
Copy Markdown
Contributor

@mqqz mqqz commented May 22, 2026

Replaces #113.

This adds tuple struct support to #[pin_data], init!, and pin_init!.

The projected form of a tuple struct is also a tuple struct, so projected fields are accessed with native tuple syntax (.0, .1, ...), which keeps the generated API closer to
ordinary Rust and avoids exposing synthetic field names (also makes it easier fields are cfg'd out).

  • tuple struct projections from #[pin_data]
  • tuple struct initialization with indexed brace syntax:
    • pin_init!(Foo { 0 <- ..., 1: ... })
  • tuple struct initialization with constructor syntax:
    • pin_init!(Foo(...))
  • support for tuple structs with generics, const generics, pinned drop, and fallible partial initialization rollback
  • support for tuple structs when fields or constructor arguments are removed by #[cfg]

Notes

  • tuple projections use native tuple field access rather than synthetic names e.g. ._0 like last time.
  • cfg handling does not try to evaluate user #[cfg] conditions in the proc macro
  • instead, the macro generates the necessary cfg-dependent layouts and lets rustc select the active branch

Tests

Added coverage for:

  • basic tuple struct projection
  • brace and constructor tuple initialization syntax
  • duplicate / missing / invalid tuple field UI failures
  • generic and const-generic tuple structs
  • #[pin] interaction with !Unpin field types
  • pinned drop
  • fallible partial-init rollback
  • cfg-stripped tuple fields
  • cfg-stripped tuple constructor arguments
  • feature-dependent cfg field layouts

Comparison with the old PR

This replaces the earlier attempt in #113.

Compared with that PR, this version is intentionally narrower and easier to review:

  • less code motion/churn overall (my code always got motion 😎)
  • fewer refactors mixed into the feature work
  • tuple projections are tuple structs instead of relying on synthetic internal/public field names
  • cfg handling was redesigned to correctly handle cfg-stripped tuple fields and constructor arguments
  • the test set was trimmed to the non-redundant cases, while keeping the important regressions and restoring the fallible partial-init rollback coverage

Closes: #85

mqqz added 4 commits May 22, 2026 22:05
Add plumbing for tuple struct support to `#[pin_data]` by generating
tuple struct projections and tuple-aware pin-data metadata.

Keep the projection API native to Rust tuple structs, so projected
fields are accessed as `.0`, `.1`, etc. instead of introducing
synthetic public field names.

Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
Expand `init!` and `pin_init!` to initialize tuple structs using both
indexed brace syntax and tuple-constructor syntax.

Add tuple-specific runtime and UI coverage for the basic initializer
forms, duplicate/missing fields, invalid indices, and syntax errors.

Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
Extend tuple-struct coverage with the semantic cases that are easiest
to review independently from the implementation changes.

Add runtime coverage for generic and const-generic tuple structs,
`Unpin` behaviour with `!Unpin` field types, pinned drop, and fallible
partial-init rollback.

Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
Handle tuple structs whose fields or constructor arguments are removed
by `#[cfg]`.

For tuple projections and tuple-constructor lowering, generate the
needed cfg-specific layouts instead of trying to evaluate user cfgs
inside the proc macro, and let rustc select the active branch.

Add regression tests covering cfg-stripped tuple fields, cfg-stripped
tuple constructor arguments, and feature-dependent field layouts.

Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc>
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