From 55cae0a094bbdcd0e9d5e697ce4f38cbd783bbc7 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Tue, 17 Jun 2014 23:25:51 -0700 Subject: Implement RFC#28: Add PartialOrd::partial_cmp 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 --- src/liballoc/owned.rs | 5 +++++ src/liballoc/rc.rs | 5 +++++ 2 files changed, 10 insertions(+) (limited to 'src/liballoc') diff --git a/src/liballoc/owned.rs b/src/liballoc/owned.rs index 33afa806f4e..addec396bbe 100644 --- a/src/liballoc/owned.rs +++ b/src/liballoc/owned.rs @@ -18,6 +18,7 @@ use core::fmt; use core::intrinsics; use core::kinds::Send; use core::mem; +use core::option::Option; use core::raw::TraitObject; use core::result::{Ok, Err, Result}; @@ -64,6 +65,10 @@ impl PartialEq for Box { fn ne(&self, other: &Box) -> bool { *(*self) != *(*other) } } impl PartialOrd for Box { + #[inline] + fn partial_cmp(&self, other: &Box) -> Option { + (**self).partial_cmp(*other) + } #[inline] fn lt(&self, other: &Box) -> bool { *(*self) < *(*other) } #[inline] diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index a3ca72f1547..0746f0a0f04 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -162,6 +162,11 @@ impl PartialEq for Rc { impl Eq for Rc {} impl PartialOrd for Rc { + #[inline(always)] + fn partial_cmp(&self, other: &Rc) -> Option { + (**self).partial_cmp(&**other) + } + #[inline(always)] fn lt(&self, other: &Rc) -> bool { **self < **other } -- cgit 1.4.1-3-g733a5