Skip to content

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

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

Open
xmh0511 opened this issue Apr 23, 2025 · 0 comments

Comments

@xmh0511
Copy link

xmh0511 commented Apr 23, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant