Uh oh!
There was an error while loading. Please reload this page.
Make #[derive(Copy, Eq, Ord)] imply #[derive(Clone, PartialEq, PartialOrd)] - #23905
Make #[derive(Copy, Eq, Ord)] imply #[derive(Clone, PartialEq, PartialOrd)]#23905erickt wants to merge 9 commits into
Conversation
rust-highfive
commented
Mar 31, 2015
(rust_highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
The derived partial_cmp can be optimized in this case to just Some(self.cmp(other)).
EDIT: Hmm, though they're not totally equivalent in the presence of type paramters unfortunately.
There was a problem hiding this comment.
Good point. I've got a build running that applies this PartialOrd optimization to non-generic types. I'll push it up when it finishes running.
aturon
commented
Mar 31, 2015
🎯 |
alexcrichton
commented
Mar 31, 2015
Out of curiosity, is it still possible to have |
sfackler
commented
Mar 31, 2015
@alexcrichton I think the more common thing would be the opposite since |
alexcrichton
commented
Mar 31, 2015
Hm true. In general I've been very worried in the past about this form of |
erickt
commented
Apr 1, 2015
@alexcrichton: with this PR we could no longer provide a manual implementation of |
nikomatsakis
commented
Apr 1, 2015
My main concern is whether this PR requires an RFC. It seems to be at least mildly controversial. Obviously this would have to land by 1.0 though! (I personally acknowledge @alexcrichton's concerns, but think that this PR is a net improvement on the current situation.) |
erickt
commented
Apr 1, 2015
@sfackler: I just pushed up a patch that simplifies generating |
nikomatsakis
commented
Apr 1, 2015
bors
commented
Apr 2, 2015
☔ The latest upstream changes (presumably #23963) made this pull request unmergeable. Please resolve the merge conflicts. |
erickt
commented
Apr 2, 2015
I rebased on top of HEAD to avoid some merge conflicts and squashed some of the cleanup commits together. |
This allows #[derive(...)]` to create more than one impl
This PR generates a simplified `PartialOrd` implementation when the
type is `Ord` and non-generic. It produces essentially:
impl ::std::cmp::PartialOrd for $ty {
fn partial_cmp(&self, other: &$ty) -> Option<std::cmp::Ordering> {
Some(::std::cmp::Ord::cmp(self, other))
}
}huonw
commented
Apr 3, 2015
Copying this comment to ensure it doesn't get lost: I believe it one should be able to make the simple-impls work via the Also, another minor point: what about supporting Alsoalso, I wonder about the case of optimising #[derive(Ord)]structFoo{ ... }and structFoo{ ... }implOrdforFoo{fncmp(&self,other:&Foo) -> Ordering{// ... lots of stuff ...}}implPartialOrdforFoo{fnpartial_cmp(&self,other:&Foo) -> Option<Ordering>{Some(self.cmp(other))}fnlt(&self,other:&Foo) -> bool{/* supafast */}}That said, it seems like this PR is the right default, and we can add an opt-out mechanism in future. |
nikomatsakis
commented
Apr 3, 2015
I thought the PR did permit this, albeit with a FIXME attached? (I tend to think we should just allow it and, at most, lint for it) |
erickt
commented
Apr 3, 2015
@nikomatsakis: Yes, this PR explicitly handles |
This extracts some of the minor cleanup patches from #23905.
huonw
commented
Apr 6, 2015
Oh, I wasn't clear: my reading of the PR was that the support for that was only for staging reasons. In any case, a lint (or nothing) sounds good to me. |
This extracts some of the minor cleanup patches from #23905.
dcrewi
commented
Apr 13, 2015
This should probably be closed now, as the RFC has been resolved? |
alexcrichton
commented
Apr 13, 2015
Yes thanks for the reminder @dcrewi! Closing for the same reasons as listed in the RFC. |
This extracts some of the minor cleanup patches from #23905.
This reduces the amount of boilerplate users need to do in order to derive some common traits.
This is related to #23860.
cc @nikomatsakis, @aturon