-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tweaks to the blanket impls of PartialEq #23521
Conversation
This does seem pretty nice to me, although I'd be somewhat wary signing off on the usage of negative trait impls here. cc @aturon, @nikomatsakis, seems coherence related? |
Regarding coherence, the new blanket impls restrict user-defined impls no more than the old impls. Except for user-defined impls for references, but that is intended. |
@petrochenkov This is quite neat, and it's one of the strategies @nikomatsakis and I have discussed for encoding specialization/negative bounds. However, we're in the midst of a (another) coherence overhaul, precisely related to negative reasoning. See #23086 for example. For that reason, I'd prefer to wait on this PR until we know for sure that this kind of negative reasoning can continue to be supported. (This will hopefully be resolved in the next few days.) |
☔ The latest upstream changes (presumably #23936) made this pull request unmergeable. Please resolve the merge conflicts. |
In addition to not fitting into the new implementation of coherence, after #23673 type inference for operator |
…richton Right now comparing a `&String` (or a `&Cow`) to a `&str` requires redundant borrowing of the latter. Implementing `PartialEq<str>` tries to avoid this limitation. ```rust struct Foo (String); fn main () { let s = Foo("foo".to_string()); match s { Foo(ref x) if x == &"foo" => println!("foo!"), // avoid this -----^ _ => {} } } ``` I was hoping that rust-lang#23521 would solve this but it didn't work out.
Right now comparing a `&String` (or a `&Cow`) to a `&str` requires redundant borrowing of the latter. Implementing `PartialEq<str>` tries to avoid this limitation. ```rust struct Foo (String); fn main () { let s = Foo("foo".to_string()); match s { Foo(ref x) if x == &"foo" => println!("foo!"), // avoid this -----^ _ => {} } } ``` I was hoping that #23521 would solve this but it didn't work out.
NOTE: This is not ready to land yet (it's blocked by #23519), but I'd like to discuss the idea.
The idea is simple - currently while doing comparisons we effectively remove references from both operands until one of the operands become non-reference and then we perform the actual comparison.
After this patch we remove references from operands until both of the operands become non-references and then perform the comparison. After the change all the concrete impls of
PartialEq
will be written for non-reference types (seevec.rs
for the most impressive consequences). The same tweak can be applied toPartialOrd
if needed.It was discussed shortly in #22320
r? @alexcrichton
cc @japaric