Skip to content

internal: add PhantomInvariant and PhantomInvariantLifetime#150

Merged
nbdd0121 merged 1 commit into
mainfrom
dev/invariant
May 14, 2026
Merged

internal: add PhantomInvariant and PhantomInvariantLifetime#150
nbdd0121 merged 1 commit into
mainfrom
dev/invariant

Conversation

@nbdd0121
Copy link
Copy Markdown
Member

@nbdd0121 nbdd0121 commented May 8, 2026

Currently, the pin_init library has an Invariant type alias, and it is instantiated using PhantomData. Generated code from pin_data on the other hand cannot access the crate-local type alias, so it generates PhantomData<fn(T) -> T> directly. This is all very inconsistent, despite the exact same use case of ensuring invariance.

Add PhantomInvariant and PhantomInvariantLifetime and switch all users that need to express the concept of invariance to use these. They're polyfills of unstable types in the same names in the Rust standard library.

Currently, the `pin_init` library has an `Invariant` type alias, and it is
instantiated using `PhantomData`. Generated code from `pin_data` on the
other hand cannot access the crate-local type alias, so it generates
`PhantomData<fn(T) -> T>` directly. This is all very inconsistent, despite
the exact same use case of ensuring invariance.

Add `PhantomInvariant` and `PhantomInvariantLifetime` and switch all users
that need to express the concept of invariance to use these. They're
polyfills of unstable types in the same names in the Rust standard library.

Signed-off-by: Gary Guo <gary@garyguo.net>
@nbdd0121 nbdd0121 force-pushed the dev/invariant branch 2 times, most recently from 43702e7 to 483a31d Compare May 14, 2026 19:21
@nbdd0121 nbdd0121 merged commit 5a4877d into main May 14, 2026
22 checks passed
@nbdd0121 nbdd0121 deleted the dev/invariant branch May 14, 2026 19:27
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.

1 participant