Tracking Issue for `#![feature(phantom_variance_markers)]`
Open
Nobody has claimed this yet.
C-tracking-issue
T-libs
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
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
- ACP: https://github.com/rust-lang/libs-team/issues/488
- Implementation: #135807
- Final comment period (FCP)^1
- Stabilization PR
Unresolved Questions
- Should there be a single
Lifetimetype or one for each possible variance? The former would mean writingPhantomCovariant<Lifetime<'a>>instead ofPhantomCovariantLifetime<'a>, with the API otherwise being identical. - Should the values be directly constructable, eliminating the need for
::new()? This would presumably mean adding 4–6 lang items, depending on the previous bullet point. - Are we happy exposing the (unstable) rustc_pub_transparent on these, allowing indirect inclusion in repr(transparent) types?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the feature-gate description, ACP rust-lang/libs-team#488, and implementation PR #135807. Review the unresolved API questions and the stabilization process linked in the issue. Done means reaching a decision on the listed questions, completing the final comment period, and preparing or reviewing the stabilization PR.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100