Skip to content

Implement RFC#28: Add PartialOrd::partial_cmp #15030

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

Merged
merged 1 commit into from
Jun 30, 2014

Conversation

sfackler
Copy link
Member

I ended up altering the semantics of Json's PartialOrd implementation.
It used to be the case that Null < Null, but I can't think of any reason
for an ordering other than the default one so I just switched it over to
using the derived implementation.

This also fixes broken PartialOrd implementations for Vec and
TreeMap.

Note

This isn't ready to merge yet since libcore tests are broken as you end up with 2 versions of Option. The rest should be reviewable though.

RFC: 0028-partial-cmp

@sfackler
Copy link
Member Author

Test compilation failures:

rustc: x86_64-unknown-linux-gnu/stage2/test/coretest-x86_64-unknown-linux-gnu
/home/sfackler/rust/rust/src/libcore/iter.rs:2222:21: 2222:37 error: mismatched types: expected `core::option::Option<core::cmp::Ordering>` but found `option::Option<<generic #426>>` (expected enum core::option::Option but found enum option::Option)
/home/sfackler/rust/rust/src/libcore/iter.rs:2222                     Some(cmp::Equal) => (),
                                                                      ^~~~~~~~~~~~~~~~
/home/sfackler/rust/rust/src/libcore/iter.rs:2223:38: 2223:44 error: mismatched types: expected `option::Option<core::cmp::Ordering>` but found `core::option::Option<core::cmp::Ordering>` (expected enum option::Option but found enum core::option::Option)
/home/sfackler/rust/rust/src/libcore/iter.rs:2223                     non_eq => return non_eq,
                                                                                       ^~~~~~
/home/sfackler/rust/rust/src/libcore/iter.rs:3036:13: 3038:14 error: method `partial_cmp` has an incompatible type for trait: expected enum core::option::Option but found enum option::Option
/home/sfackler/rust/rust/src/libcore/iter.rs:3036             fn partial_cmp(&self, _: &Foo) -> Option<Ordering> {
/home/sfackler/rust/rust/src/libcore/iter.rs:3037                 None
/home/sfackler/rust/rust/src/libcore/iter.rs:3038             }
/home/sfackler/rust/rust/src/libcore/option.rs:151:30: 151:40 error: mismatched types: expected `core::option::Option<core::cmp::Ordering>` but found `option::Option<core::cmp::Ordering>` (expected enum core::option::Option but found enum option::Option)
/home/sfackler/rust/rust/src/libcore/option.rs:151 #[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Show)]
                                                                                ^~~~~~~~~~
note: in expansion of #[deriving]
/home/sfackler/rust/rust/src/libcore/option.rs:151:1: 152:4 note: expansion site
/home/sfackler/rust/rust/src/libcore/option.rs:151:30: 151:40 error: if and else have incompatible types: expected `option::Option<core::cmp::Ordering>` but found `core::option::Option<core::cmp::Ordering>` (expected enum core::option::Option but found enum option::Option)
/home/sfackler/rust/rust/src/libcore/option.rs:151 #[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Show)]
                                                                                ^~~~~~~~~~
note: in expansion of #[deriving]
/home/sfackler/rust/rust/src/libcore/option.rs:151:1: 152:4 note: expansion site
/home/sfackler/rust/rust/src/libcore/option.rs:151:30: 151:40 error: method `partial_cmp` has an incompatible type for trait: expected enum core::option::Option but found enum option::Option
/home/sfackler/rust/rust/src/libcore/option.rs:151 #[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Show)]
                                                                                ^~~~~~~~~~
note: in expansion of #[deriving]
/home/sfackler/rust/rust/src/libcore/option.rs:151:1: 152:4 note: expansion site
/home/sfackler/rust/rust/src/libcore/result.rs:286:30: 286:40 error: mismatched types: expected `core::option::Option<core::cmp::Ordering>` but found `option::Option<core::cmp::Ordering>` (expected enum core::option::Option but found enum option::Option)
/home/sfackler/rust/rust/src/libcore/result.rs:286 #[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Show)]
                                                                                ^~~~~~~~~~
note: in expansion of #[deriving]
/home/sfackler/rust/rust/src/libcore/result.rs:286:1: 287:2 note: expansion site
/home/sfackler/rust/rust/src/libcore/result.rs:286:30: 286:40 error: if and else have incompatible types: expected `option::Option<core::cmp::Ordering>` but found `core::option::Option<core::cmp::Ordering>` (expected enum core::option::Option but found enum option::Option)
/home/sfackler/rust/rust/src/libcore/result.rs:286 #[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Show)]
                                                                                ^~~~~~~~~~
note: in expansion of #[deriving]
/home/sfackler/rust/rust/src/libcore/result.rs:286:1: 287:2 note: expansion site
/home/sfackler/rust/rust/src/libcore/result.rs:286:30: 286:40 error: mismatched types: expected `core::option::Option<core::cmp::Ordering>` but found `option::Option<core::cmp::Ordering>` (expected enum core::option::Option but found enum option::Option)
/home/sfackler/rust/rust/src/libcore/result.rs:286 #[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Show)]
                                                                                ^~~~~~~~~~
note: in expansion of #[deriving]
/home/sfackler/rust/rust/src/libcore/result.rs:286:1: 287:2 note: expansion site
/home/sfackler/rust/rust/src/libcore/result.rs:286:30: 286:40 error: if and else have incompatible types: expected `option::Option<core::cmp::Ordering>` but found `core::option::Option<core::cmp::Ordering>` (expected enum core::option::Option but found enum option::Option)
/home/sfackler/rust/rust/src/libcore/result.rs:286 #[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Show)]
                                                                                ^~~~~~~~~~
note: in expansion of #[deriving]
/home/sfackler/rust/rust/src/libcore/result.rs:286:1: 287:2 note: expansion site
/home/sfackler/rust/rust/src/libcore/result.rs:286:30: 286:40 error: method `partial_cmp` has an incompatible type for trait: expected enum core::option::Option but found enum option::Option
/home/sfackler/rust/rust/src/libcore/result.rs:286 #[deriving(Clone, PartialEq, PartialOrd, Eq, Ord, Show)]
                                                                                ^~~~~~~~~~
note: in expansion of #[deriving]
/home/sfackler/rust/rust/src/libcore/result.rs:286:1: 287:2 note: expansion site
error: aborting due to 11 previous errors
/home/sfackler/rust/rust/mk/tests.mk:384: recipe for target 'x86_64-unknown-linux-gnu/stage2/test/coretest-x86_64-unknown-linux-gnu' failed
make: *** [x86_64-unknown-linux-gnu/stage2/test/coretest-x86_64-unknown-linux-gnu] Error 101

@thestinger
Copy link
Contributor

JSON objects are unordered key-value maps, and I don't really like that we've extended it with ordering semantics based on key comparisons. I've only ever seen JSON objects mapped to hash tables, not ordered maps (except in C++98, where there was no standard hash table). I wouldn't worry much about trying to get that ordering right, because I don't think it's a good idea to be doing it in the first place.

@alexcrichton
Copy link
Member

r=me when coretest is passing, thanks!

@sfackler
Copy link
Member Author

It seems like the right way forward here is to extract libcore's tests to a separate crate. I'm working on that now, and this can go in on top of that.

@@ -154,20 +160,57 @@ pub fn lexical_ordering(o1: Ordering, o2: Ordering) -> Ordering {
/// 5.11).
#[lang="ord"]
pub trait PartialOrd: PartialEq {
/// This method returns an ordering between `self` and `other` values
/// if one exists.
#[cfg(stage0)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, why does this need staging?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The snapshot's deriving won't generate partial_cmp so there needs to be a default impl.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, tricky!

I ended up altering the semantics of Json's PartialOrd implementation.
It used to be the case that Null < Null, but I can't think of any reason
for an ordering other than the default one so I just switched it over to
using the derived implementation.

This also fixes broken `PartialOrd` implementations for `Vec` and
`TreeMap`.

RFC: 0028-partial-cmp
@sfackler
Copy link
Member Author

@huonw updated

bors added a commit that referenced this pull request Jun 30, 2014
I ended up altering the semantics of Json's PartialOrd implementation.
It used to be the case that Null < Null, but I can't think of any reason
for an ordering other than the default one so I just switched it over to
using the derived implementation.

This also fixes broken `PartialOrd` implementations for `Vec` and
`TreeMap`.

# Note
This isn't ready to merge yet since libcore tests are broken as you end up with 2 versions of `Option`. The rest should be reviewable though.

RFC: 0028-partial-cmp
@bors bors closed this Jun 30, 2014
@bors bors merged commit 55cae0a into rust-lang:master Jun 30, 2014
cadencemarseille added a commit to cadencemarseille/rust-pcre that referenced this pull request Jul 1, 2014
@sfackler sfackler deleted the partial-cmp branch November 26, 2016 05:53
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 17, 2023
ci(metrics): Run measurement functions in parallel

Resolves rust-lang#14853
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants