-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
infer or permit declarations of variance for type parameters #281
Comments
Closed due to #738 being accepted. |
withoutboats
pushed a commit
to withoutboats/rfcs
that referenced
this issue
Jan 15, 2017
Fix most of the doc links in Tutorial
wycats
pushed a commit
to wycats/rust-rfcs
that referenced
this issue
Mar 5, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue by nikomatsakis
Wednesday Sep 26, 2012 at 18:51 GMT
For earlier discussion, see rust-lang/rust#3598
This issue was labelled with: A-typesystem, B-clarifying, B-RFC, E-mentor, P-high in the Rust repository
UPDATE
Variance inference is complete.
What is still missing is:
ORIGINAL
Today, we treat all type parameters as invariant, but infer variance for region parameters. We can use that same code which infers the variance for region parameters to infer the suitable variance for type parameters if we like.
Alternatively, if we decide that inference here is too magical, we could require explicit declaration of variance. In that case, i'd favor covariance as the default, and the possibility to write
struct Foo<mut T>
to indicate an invariant type parameterT
(which can appear in mutable locations). This seems more intuitive than the usual+
and-
. We probably don't need a notation for contravariance, but in that case perhapsfn T
(to indicate a type parameter that appears only in function arguments, far and away the most common place to have a contravariant type parameter).Still, I think I favor inference. It's inline with what we do for regions and I think it will basically match up with user expectations.
The text was updated successfully, but these errors were encountered: