You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, we don't have any kind of programmatic way of ensuring that we don't accidentally change the variances of any libcore/libstd types. While some types do have explicit tests for variance (e.g. here and in PR #72902), this is not done in any kind of systematic way.
I think it would be useful to have an internal #[variance(Co/Contra/In)] (names bikesheddable) which causes an error if the actual and expected variances do not match.
We could require that every generic parameter on every public type have a #[variance] attribute, similar to how we require #[stable]/#[unstable]. However, this could end up being unnecessarily verbose, especially if most types are covariant. Instead, we might want to treat the absence of a #[variance] annotation as an implicit #[variance(Covariant)] (or #[variance(Invariant)] for const generics). If covariance is normally what we want, then this would only require us to annotate cases where something 'unusual' is happening. Of course, we would run the risk of cases like #71814 'slipping under the radar', where the generic parameter really should have been invariant to begin with.
The text was updated successfully, but these errors were encountered:
where the generic parameter really should have been invariant to begin with.
Not completely relevant to this issue, but I disagree here. Discriminant would still be completely sound even if it were bivariant, which it should be IMO.
Apart from this, I do agree that we should have an easy way to guard against variance changes.
Currently, we don't have any kind of programmatic way of ensuring that we don't accidentally change the variances of any
libcore
/libstd
types. While some types do have explicit tests for variance (e.g. here and in PR #72902), this is not done in any kind of systematic way.I think it would be useful to have an internal
#[variance(Co/Contra/In)]
(names bikesheddable) which causes an error if the actual and expected variances do not match.We could require that every generic parameter on every public type have a
#[variance]
attribute, similar to how we require#[stable]
/#[unstable]
. However, this could end up being unnecessarily verbose, especially if most types are covariant. Instead, we might want to treat the absence of a#[variance]
annotation as an implicit#[variance(Covariant)]
(or#[variance(Invariant)]
for const generics). If covariance is normally what we want, then this would only require us to annotate cases where something 'unusual' is happening. Of course, we would run the risk of cases like #71814 'slipping under the radar', where the generic parameter really should have been invariant to begin with.The text was updated successfully, but these errors were encountered: