Overly restrictive variance #32
Labels
A-generic-exprs
Generic const expressions
A-unification
Unifying constants in the type system
C-design-docs
Category: This is part of our design documentation
K-behavior
Document Kind: regarding user visible behavior
P-optional
Priority: not strictly required
S-blocked
What is this
This is a design document for const generics. Any discussions about its content should be on zulip. The conclusions of these discussions should then be edited back into this issue. Please do not post any comments directly in this issue.
Content
Currently all generic parameters used by constants in the type system are constrained
to be invariant. Looking at this example, that is unnecessary:
Here
'a
is forced to be invariant, as it is used in the anonymous constant, butideally it should be covariant.
How variance can influence CTFE
The most obvious example is
TypeId::of
which has to differ betweenfor<'a> fn(&'a ())
andfn(&'static ())
andfor<'a> fn(fn(&'a ())
andfn(fn(&'static ())
.Higher ranked types act different during candidate selection and can therefore not simply be ignored. We currently have a future compatability lint for this in #56105 which will probably get allowed in the future.
The text was updated successfully, but these errors were encountered: