From 666dd57c807a97177125cbf7f2365837d2c1e8eb Mon Sep 17 00:00:00 2001 From: Geordon Worley Date: Sun, 1 May 2016 04:07:47 -0400 Subject: [PATCH 1/2] fix implementation of Ord for Cell and RefCell where T: Ord --- src/libcore/cell.rs | 74 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 257027dad5ed2..57c3d9bd2fb22 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -145,7 +145,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use clone::Clone; -use cmp::{PartialEq, Eq}; +use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering}; use default::Default; use marker::{Copy, Send, Sync, Sized, Unsize}; use ops::{Deref, DerefMut, Drop, FnOnce, CoerceUnsized}; @@ -267,6 +267,42 @@ impl PartialEq for Cell { #[stable(feature = "cell_eq", since = "1.2.0")] impl Eq for Cell {} +#[unstable(feature = "cell_ord", issue = "33305")] +impl PartialOrd for Cell { + #[inline] + fn partial_cmp(&self, other: &Cell) -> Option { + self.get().partial_cmp(&other.get()) + } + + #[inline] + fn lt(&self, other: &Cell) -> bool { + self.get() < other.get() + } + + #[inline] + fn le(&self, other: &Cell) -> bool { + self.get() <= other.get() + } + + #[inline] + fn gt(&self, other: &Cell) -> bool { + self.get() > other.get() + } + + #[inline] + fn ge(&self, other: &Cell) -> bool { + self.get() >= other.get() + } +} + +#[unstable(feature = "cell_ord", issue = "33305")] +impl Ord for Cell { + #[inline] + fn cmp(&self, other: &Cell) -> Ordering { + self.get().cmp(&other.get()) + } +} + /// A mutable memory location with dynamically checked borrow rules /// /// See the [module-level documentation](index.html) for more. @@ -490,6 +526,42 @@ impl PartialEq for RefCell { #[stable(feature = "cell_eq", since = "1.2.0")] impl Eq for RefCell {} +#[unstable(feature = "cell_ord", issue = "33305")] +impl PartialOrd for RefCell { + #[inline] + fn partial_cmp(&self, other: &RefCell) -> Option { + self.borrow().partial_cmp(&*other.borrow()) + } + + #[inline] + fn lt(&self, other: &RefCell) -> bool { + *self.borrow() < *other.borrow() + } + + #[inline] + fn le(&self, other: &RefCell) -> bool { + *self.borrow() <= *other.borrow() + } + + #[inline] + fn gt(&self, other: &RefCell) -> bool { + *self.borrow() > *other.borrow() + } + + #[inline] + fn ge(&self, other: &RefCell) -> bool { + *self.borrow() >= *other.borrow() + } +} + +#[unstable(feature = "cell_ord", issue = "33305")] +impl Ord for RefCell { + #[inline] + fn cmp(&self, other: &RefCell) -> Ordering { + self.borrow().cmp(&*other.borrow()) + } +} + struct BorrowRef<'b> { borrow: &'b Cell, } From 4dcb63707eae97032254c18204b0f64b002b9cca Mon Sep 17 00:00:00 2001 From: Geordon Worley Date: Sun, 1 May 2016 04:26:39 -0400 Subject: [PATCH 2/2] change unstable to stable on traits and set version properly --- src/libcore/cell.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 57c3d9bd2fb22..84896eb6fd792 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -267,7 +267,7 @@ impl PartialEq for Cell { #[stable(feature = "cell_eq", since = "1.2.0")] impl Eq for Cell {} -#[unstable(feature = "cell_ord", issue = "33305")] +#[stable(feature = "cell_ord", since = "1.10.0")] impl PartialOrd for Cell { #[inline] fn partial_cmp(&self, other: &Cell) -> Option { @@ -295,7 +295,7 @@ impl PartialOrd for Cell { } } -#[unstable(feature = "cell_ord", issue = "33305")] +#[stable(feature = "cell_ord", since = "1.10.0")] impl Ord for Cell { #[inline] fn cmp(&self, other: &Cell) -> Ordering { @@ -526,7 +526,7 @@ impl PartialEq for RefCell { #[stable(feature = "cell_eq", since = "1.2.0")] impl Eq for RefCell {} -#[unstable(feature = "cell_ord", issue = "33305")] +#[stable(feature = "cell_ord", since = "1.10.0")] impl PartialOrd for RefCell { #[inline] fn partial_cmp(&self, other: &RefCell) -> Option { @@ -554,7 +554,7 @@ impl PartialOrd for RefCell { } } -#[unstable(feature = "cell_ord", issue = "33305")] +#[stable(feature = "cell_ord", since = "1.10.0")] impl Ord for RefCell { #[inline] fn cmp(&self, other: &RefCell) -> Ordering {