Skip to content

The reference lacks the specification about the variance of lifetime parameters that have different variances in each position #1801

@xmh0511

Description

@xmh0511

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>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions