Uh oh!
There was an error while loading. Please reload this page.
Add a generic From<&Borrow> impl for Cow - #48191
Conversation
rust-highfive
commented
Feb 13, 2018
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 CowFrom<&Borrow> impl for Cowegilburg
commented
Feb 13, 2018
Does this replace a stable function with an unstable one? |
burtonageo
commented
Feb 13, 2018
@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. |
egilburg
commented
Feb 13, 2018
@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? |
burtonageo
commented
Feb 13, 2018
@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 |
shepmaster
commented
Feb 17, 2018
Ping from triage, @alexcrichton — will you be able to give this a review sometime soon? |
Mark-Simulacrum
commented
Feb 17, 2018
I believe @alexcrichton is mostly absent for a few weeks, so r? @BurntSushi |
BurntSushi
commented
Feb 17, 2018
r? @aturon |
emilyalbini
commented
Feb 26, 2018
@aturon, or someone else from @rust-lang/libs, can we get a review on this PR? |
alexcrichton
commented
Feb 26, 2018
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. |
burtonageo
commented
Feb 27, 2018
@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. |
withoutboats
commented
Feb 27, 2018
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)]structX;impl<'a>From<&'aX>forCow<'a,X>{fnfrom(x:&'aX) -> Self{Cow::Borrowed(x)}} |
alexcrichton
commented
Feb 27, 2018
@bors: try @rust-lang/infra could a crate run be scheduled for this PR? |
bors
commented
Feb 27, 2018
⌛ Trying commit 75bf333 with merge 1864114421fdd4165e02ca3ad67dfc6e42174ba3... |
bors
commented
Feb 27, 2018
☀️ Test successful - status-travis |
Mark-Simulacrum
commented
Mar 4, 2018
Crater started |
Mark-Simulacrum
commented
Mar 10, 2018
Crater results: http://cargobomb-reports.s3.amazonaws.com/pr-48191/index.html. 'Blacklisted' crates (spurious failures etc) can be found |
alexcrichton
commented
Mar 14, 2018
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 genericFromimpl 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 reflexiveFromimpl in core. Thus, those impls will still have to be implemented in an ad-hoc way until maybe specialization could solve it.