Skip to content

internal: add PhantomInvariant and PhantomInvariantLifetime#150

Open
nbdd0121 wants to merge 1 commit intomainfrom
dev/invariant
Open

internal: add PhantomInvariant and PhantomInvariantLifetime#150
nbdd0121 wants to merge 1 commit intomainfrom
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>
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