-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
remove weird contravariant #134237
remove weird contravariant #134237
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you actually try looking at the PR that introduced it? You tried to change this a year ago with no justification, and there's still no justification other than you not understanding why it's there: 1bf3aee#r1447618595
I'm fairly certain that changing PhantomData<fn(&I)>
to PhantomData<I>
changes the implications of the type w.r.t. drop, and obviously changes the variance of the I
parameter.
I don't believe that this should be changed for literally no reason.
do you mean this one? #34149 I don't see anywhere explained why they went with that.
I did not understand it then, I don't understand it now that I know more and it's been somewhere in the back of my mind since. |
It's a pretty common pattern to make map-like type constructors contravariant in the key type parameter. Apart from being conventional (across all languages that feature contravariance), it can be convenient at times (in Rust, it probably tends towards the rarer side in practice). The "academic" answer: Maps of type In more "practical" terms, it permits you to for example treat |
Regarding Also, |
idk so i guess r? compiler-errors |
I suggest the following:
|
I'm going to close this, it's been explained why preferring |
I'm not sure what purpose this
PhantomData<fn(&I)>
has, it looks like it wants a contravariant for some reason but... why? It's confusing, does it have any purpose? If it does not let's just remove it.