Uh oh!
There was an error while loading. Please reload this page.
Generalise slice::contains over PartialEq - #46934
Conversation
This allows `contains` to be used on slices to search for elements that satisfy a partial equality with the slice item type, rather than an identity. This closesrust-lang#42671. Note that string literals need to be referenced in this implementation due to `str` not implementing `Sized`. It’s likely this will have to go through a Crater run to test for breakage (see rust-lang#43020).
rust-highfive
commented
Dec 22, 2017
r? @bluss (rust_highfive has picked a reviewer for you, use r? to override) |
varkor
commented
Dec 22, 2017
Investigating the issue with |
The issue here is that some crates define I'm not sure of the best way to address this problem: I think we certainly want to warn/error against non-symmetric partial equalities (or implement them automatically), but that would take time. Can you think of any ways to get around this that wouldn't involve updating the incorrect crates? EDIT: On the other hand, if a crate has previously used |
CAD97
commented
Dec 22, 2017
I think I may have found a way to make this work... A reduction of what this implementation ran into: (playground link) traitContains<T>whereT: ?Sized,{fncontains<U>(&self,x:&U) -> boolwhereT:PartialEq<U>,U: ?Sized,{true}}impl<'a,T>Contains<T>for&'a[T]{}#[test]fntest(){let a:&str = "string";let v:&[&str] = &[a];Contains::contains(&v, a);}In these types, we have fncontains<'a,U>(&self,x:&'aU) -> boolwhereT:PartialEq<&'aU>The other choice is to go the other way and make the reference part of the fn contains<U>&self, x:U) -> boolwhereT:PartialEq<U>I think this is the solution that we want to use here, assuming it works, but one of the two definitely should. @varkor ? On The only impl that doesn't involve non- |
varkor
commented
Dec 23, 2017
@CAD97: In order to conserve the behaviour of type signature of Regarding the question about the nonexistence of |
CAD97
commented
Dec 23, 2017
OK, I missed some of the complexity here, due to only working with my minimized example. Here's an updated small example: playground. |
varkor
commented
Dec 23, 2017
After implementing |
kennytm
commented
Dec 27, 2017
@bors try |
bors
commented
Dec 27, 2017
Generalise slice::contains over PartialEq This allows `contains` to be used on slices to search for elements that satisfy a partial equality with the slice item type, rather than an identity. This closes#42671. Note that string literals need to be referenced in this implementation due to `str` not implementing `Sized`. It’s likely this will have to go through a Crater run to test for breakage (see #43020).
bors
commented
Dec 27, 2017
☀️ Test successful - status-travis |
kennytm
commented
Jan 2, 2018
@aidanhs@Mark-Simulacrum This needs a crater run (new= |
aidanhs
commented
Jan 4, 2018
Crater run started. |
varkor
commented
Jan 4, 2018
#46713 has broken this implementation. I'll figure out what to do if the Crater run has a positive outcome, because a fix is non-trivial. |
aidanhs
commented
Jan 9, 2018
Crater run failed and started again (workaround for the issue has been put in place). |
varkor
commented
Jan 12, 2018
Okay, it's quite clear that this causes a ton of type inference issues. Breakage is probably not worth the benefit. I'll close and mark #42671 as unlikely to be fixed if there are no other reservations? |
bluss
commented
Jan 13, 2018
Just to showcase why naked unqalified This code would want this PR, to use A whole large part of the crater issues are exactly like that, and it's a shame they are blocking themselves from improving. There are other less simple cases though. |
leoyvens
commented
Jan 13, 2018
I suppose default type parameter fallback would allow this by setting |
aidanhs
commented
Jan 18, 2018
I'm going to go ahead and close this PR, looks like another approach is being discussed over at the original issue though. |
This allows
containsto be used on slices to search for elements thatsatisfy a partial equality with the slice item type, rather than an
identity. This closes#42671. Note that string literals need to be
referenced in this implementation due to
strnot implementingSized. It’s likely this will have to go through a Crater run to testfor breakage (see #43020).