-
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
Add a generic From<&Borrow>
impl for Cow
#48191
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
From<Borrow>
impl for Cow
From<&Borrow>
impl for Cow
Does this replace a stable function with an unstable one? |
@egilburg I believe that trait impl blocks aren't checked for stability, so I think it could be made stable. Furthermore, this impl should cover strictly more cases than the original impls do, so there should be no source breakage with this change. |
@burtonageo Fair enough, it's just that currently the code is marked "unstable", so is the marker even needed if it's not actually taking effect, and especially since it logically needs to be stable to preserve existing behavior? |
@egilburg It was just a way to mark it as WIP, but I guess there's not much point marking it as unstable, so I'll update it now |
Ping from triage, @alexcrichton — will you be able to give this a review sometime soon? |
I believe @alexcrichton is mostly absent for a few weeks, so r? @BurntSushi |
r? @aturon |
@aturon, or someone else from @rust-lang/libs, can we get a review on this PR? |
Thanks for the PR @burtonageo! I think technically this is a breaking change, right? As such, I think we may want to get a crater run to assess breakage, but would want to confirm first you agree that it's a breaking change. |
@alexcrichton Thanks for the review! According to the rfc on breaking changes (under the section "generalising to generics"), I believe this counts as a minor semver change. However, that section does state that this change could create type inference failures, and thus I agree that this is a breaking change. |
I believe this is a breaking change (not one we usually allow). It would be incoherent with implementations like this, which are allowed: #[derive(Clone)]
struct X;
impl<'a> From<&'a X> for Cow<'a, X> {
fn from(x: &'a X) -> Self {
Cow::Borrowed(x)
}
} |
@bors: try @rust-lang/infra could a crate run be scheduled for this PR? |
⌛ Trying commit 75bf333 with merge 1864114421fdd4165e02ca3ad67dfc6e42174ba3... |
☀️ Test successful - status-travis |
Crater started |
Crater results: http://cargobomb-reports.s3.amazonaws.com/pr-48191/index.html. 'Blacklisted' crates (spurious failures etc) can be found |
Thanks for the crater run! I glanced at all the git-related logs at the bottom and they're all breaking due to this change, so unfortunately looks like we won't be able to do this. |
…chton Implement From for more types on Cow This is basically rust-lang#48191, except that it should be implemented in a way that doesn't break third party crates.
This commit removes the ad-hoc impls of
From<&Borrow> for Cow
, and replaces them with a genericFrom
impl across all&Borrow<T>
. I am unsure of how the stability attributes should work, so I will need some guidance to get this in good shape to submit.The practical effects of this commit are:
From<&Borrow>
impls derived forCow<CStr>
andCow<OsStr>
, as well as any other ecosystem types that can be borrowed (e.g. ascii types)From<&Owned>
is now auto implemented. This fixes some issues with usingInto<Cow<T>>
in generic situations, as shown in this playground.Some other issues:
impl<T: ToOwned> From<T::Owned> for Cow<T>
, however it conflicted with the reflexiveFrom
impl in core. Thus, those impls will still have to be implemented in an ad-hoc way until maybe specialization could solve it.