Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upMake #[derive(Copy, Eq, Ord)] imply #[derive(Clone, PartialEq, PartialOrd)] #23905
Conversation
rust-highfive
assigned
nikomatsakis
Mar 31, 2015
This comment has been minimized.
This comment has been minimized.
|
(rust_highfive has picked a reviewer for you, use r? to override) |
sfackler
reviewed
Mar 31, 2015
| PartialCmpOp, LtOp, LeOp, GtOp, GeOp, | ||
| trait_def.expand(cx, mitem, item, push); | ||
|
|
||
| partial_ord::expand_deriving_partial_ord(cx, span, mitem, item, push) |
This comment has been minimized.
This comment has been minimized.
sfackler
Mar 31, 2015
Member
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.
This comment has been minimized.
This comment has been minimized.
erickt
Mar 31, 2015
Author
Contributor
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.
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Out of curiosity, is it still possible to have |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton I think the more common thing would be the opposite since |
This comment has been minimized.
This comment has been minimized.
|
Hm true. In general I've been very worried in the past about this form of |
This comment has been minimized.
This comment has been minimized.
|
@alexcrichton: with this PR we could no longer provide a manual implementation of |
This comment has been minimized.
This comment has been minimized.
|
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.) |
This comment has been minimized.
This comment has been minimized.
|
@sfackler: I just pushed up a patch that simplifies generating |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
erickt
force-pushed the
erickt:copy
branch
from
bdf418d
to
a14f3a5
Apr 2, 2015
This comment has been minimized.
This comment has been minimized.
|
I rebased on top of HEAD to avoid some merge conflicts and squashed some of the cleanup commits together. |
erickt
added some commits
Mar 27, 2015
erickt
force-pushed the
erickt:copy
branch
from
a14f3a5
to
eed443b
Apr 2, 2015
erickt
referenced this pull request
Apr 2, 2015
Merged
Allow #[derive(...)] methods to generate multiple items, and other cleanup #23985
This comment has been minimized.
This comment has been minimized.
huonw
commented on src/libsyntax/ext/deriving/cmp/ord.rs in eed443b
Apr 3, 2015
|
Missing |
This comment has been minimized.
This comment has been minimized.
|
Good catch! |
This comment has been minimized.
This comment has been minimized.
huonw
commented on src/libsyntax/ext/deriving/cmp/ord.rs in eed443b
Apr 3, 2015
|
I believe it should be able to made work via the |
This comment has been minimized.
This comment has been minimized.
|
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)]
struct Foo { ... }and struct Foo { ... }
impl Ord for Foo {
fn cmp(&self, other: &Foo) -> Ordering {
// ... lots of stuff ...
}
}
impl PartialOrd for Foo {
fn partial_cmp(&self, other: &Foo) -> Option<Ordering> { Some(self.cmp(other)) }
fn lt(&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. |
This comment has been minimized.
This comment has been minimized.
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) |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis: Yes, this PR explicitly handles |
bors
added a commit
that referenced
this pull request
Apr 6, 2015
This comment has been minimized.
This comment has been minimized.
|
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. |
bors
added a commit
that referenced
this pull request
Apr 7, 2015
This was referenced Apr 8, 2015
This comment has been minimized.
This comment has been minimized.
|
This should probably be closed now, as the RFC has been resolved? |
This comment has been minimized.
This comment has been minimized.
|
Yes thanks for the reminder @dcrewi! Closing for the same reasons as listed in the RFC. |
erickt commentedMar 31, 2015
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