-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Make Cow
covariant w.r.t ToOwned::Owned
#96312
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
The job Click to see the possible cause of the failure (guessed by this bot)
|
Oh no! Most failures are changed error messages, but also this:
Seems like this relates to #27336
and |
This PR makes
Cow
covariant w.r.tToOwned::Owned
, by using the trick from #57440 (moving the associated type to parameter with a default):So, for example, this will now compile:
I'm not really sure this is a good idea: it makes
Cow
's definition more complex,it's a terrible hack, and it's not really clear to me if bad things can happen if someone tries to "use" the new generic parameter, and it's possible someone is relying on the fact that
Cow
is invariant w.r.tOwned
.However, I ran into this years ago when working on a crate which tries to minimize copying,
and got super confused by scary lifetimes errors.
This is usually caused by something like
struct S1<'a> { c: Cow<'a, str> }; struct S2<'a> { c: Cow<'a, S1<'a>> }
(Link to playground).(This was previously impossible because of #79224)
PS
See #21726 (comment) and #59875 (comment) on why this is probably not true in the general case for associated types.