rust-lang / rust-lang/reference
The reference lacks the specification about the variance of lifetime parameters that have different variances in each position
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.6k
- Forks
- 607
- PR merge metrics
- PR metrics pending
Description
subtyping.variance.user-composite-types has a wording
If the parameter is used in positions with different variances then the parameter is invariant.
However, it applies only to struct, enum, and union types
subtyping.variance.builtin-composite-types specifies the rules
When used outside of an struct, enum, or union, the variance for parameters is checked at each location separately.
However, it seems to only apply to tuple and function types.
Consider this type
struct A<'a>(&'a ());
type F<'b> = &'b mut A<'b>
The reference lacks the wording to specify the variance of lifetime 'b. That is, in &'b T, 'b is covariant and T is invariant.
It seems that 'b is expected to be invariant in type &'b mut A<'b>.
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 with the linked subtyping.variance.user-composite-types and subtyping.variance.builtin-composite-types sections in the Rust Reference, comparing their stated scope and rules. Clarify how variance is specified for &'b mut A<'b>, including the lifetime and type parameter positions, so the reference fully covers this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100