-
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
Introduce variance for type parameters, not just region parameters #233
Conversation
Another potential alternative to the lint would be to to forbid unused type and lifetime parameters completely and add |
Good point. I meant to include that as an option. I agree it's |
Perhaps I am misunderstanding, but this would forbid things like |
Ah, I remember now why I opted for the lint -- because in some
put a marker? Of course, this could also be interpreted as an argument |
It would require that phantom types be written with a marker,
This could be avoided by having some sort of default choice (as On Wed, Sep 10, 2014, at 05:40 PM, Jonathan Reem wrote: Perhaps I am misunderstanding, but this would forbid things — References |
That's an important use-case too, rust-typemap, for instance, has a phantom type in the |
Yes, the workaround for traits is particularly bad:
On Wed, Sep 10, 2014, at 05:52 PM, Jonathan Reem wrote: That's an important use-case too, rust-typemap, for — References |
Given the choice between phantom lifetimes in traits work and having |
Are phantom lifetimes in traits even possible with this proposal? |
6357402
to
e0acdf4
Compare
So, @pnkfelix and I were chatting over IRC, and we realize that we can use where clauses to specify variance in all cases in a much nicer way than markers, without building things into the syntax. The idea is basically to use marker traits. These traits would be implemented for all types, and would be known to the variance analysis, just as marker types are today. We could either choose to make them an exception -- that is, the only traits for which Anyway, long story short you would write things like the following:
Since traits only apply to types, you can specify the variance of a lifetime parameter by "packaging it up" in a synthetic reference type:
This is arguably more natural, since you don't have to think about the fact that lifetimes are naturally "contravariant". Plausibly we could rename these traits to something else. I was thinking I'm going to close this RFC, explore that idea, and open a new one. |
Add a BiLock<T> type for two-way ownership
In short,
Option<&'static T>
ought to be usable whereOption<&'a T>
is expected. These changes have been fully implemented.Rendered view.