Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking Issue for #![feature(phantom_variance_markers)] #135806

Open
1 of 4 tasks
jhpratt opened this issue Jan 21, 2025 · 0 comments
Open
1 of 4 tasks

Tracking Issue for #![feature(phantom_variance_markers)] #135806

jhpratt opened this issue Jan 21, 2025 · 0 comments
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@jhpratt
Copy link
Member

jhpratt commented Jan 21, 2025

Feature gate: #![feature(phantom_variance_markers)]

This is a tracking issue for phantom variance markers, which are identical to PhantomData but provide a self-documenting variance rather than contrived types such as PhantomData<fn() -> T> to indicate contravariance.

Public API

// in core::marker

pub struct PhantomCovariant<T: ?Sized>(/* ... */);
pub struct PhantomInvariant<T: ?Sized>(/* ... */);
pub struct PhantomContravariant<T: ?Sized>(/* ... */);
pub struct PhantomCovariantLifetime<'a>(/* ... */);
pub struct PhantomInvariantLifetime<'a>(/* ... */);
pub struct PhantomContravariantLifetime<'a>(/* ... */);

pub trait Variance: Sealed {}
impl<T: ?Sized> Variance for PhantomCovariant<T> {}
impl<T: ?Sized> Variance for PhantomInvariant<T> {}
impl<T: ?Sized> Variance for PhantomContravaiant<T> {}
impl<T: ?Sized> Variance for PhantomCovariantLifetime<T> {}
impl<T: ?Sized> Variance for PhantomInvariantLifetime<T> {}
impl<T: ?Sized> Variance for PhantomContravaiantLifetime<T> {}

pub fn variance<T: Variance>() -> T {}

// also the trait impls you would expect; identical to PhantomData

Steps / History

Unresolved Questions

  • Should there be a single Lifetime type or one for each possible variance? The former would mean writing PhantomCovariant<Lifetime<'a>> instead of PhantomCovariantLifetime<'a>, with the API otherwise being identical.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@jhpratt jhpratt added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant