-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
associated types in generics cause lifetime invariance #115799
Comments
The answer is that "that's just how associated types work", when you have Again, I don't have the best insight here, but that's how I see it. Another part to this (thanks to @danielhenrymantilla for suggesting), is that if you want struct S<I: Iterator>(I::Item); You'll have to have |
You could imagine a rule that preserves covariance over type parameters if avoiding bivariance is a goal. Hopefully t-types folks can chime in. |
Batted this around with ChatGPT:
real world example: #57440 |
playground
It's not clear to me why
Holder
andCovariantHolder
are any different. It's not possible construct aCovariantHolder<T, S>
whereS
is anything other than<T as WithAssoc>::Assoc
. Why does the compiler treat them differently?The text was updated successfully, but these errors were encountered: