Skip to content

Commit 666dd57

Browse files
committed
fix implementation of Ord for Cell<T> and RefCell<T> where T: Ord
1 parent 2a815a2 commit 666dd57

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

src/libcore/cell.rs

+73-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
#![stable(feature = "rust1", since = "1.0.0")]
146146

147147
use clone::Clone;
148-
use cmp::{PartialEq, Eq};
148+
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
149149
use default::Default;
150150
use marker::{Copy, Send, Sync, Sized, Unsize};
151151
use ops::{Deref, DerefMut, Drop, FnOnce, CoerceUnsized};
@@ -267,6 +267,42 @@ impl<T:PartialEq + Copy> PartialEq for Cell<T> {
267267
#[stable(feature = "cell_eq", since = "1.2.0")]
268268
impl<T:Eq + Copy> Eq for Cell<T> {}
269269

270+
#[unstable(feature = "cell_ord", issue = "33305")]
271+
impl<T:PartialOrd + Copy> PartialOrd for Cell<T> {
272+
#[inline]
273+
fn partial_cmp(&self, other: &Cell<T>) -> Option<Ordering> {
274+
self.get().partial_cmp(&other.get())
275+
}
276+
277+
#[inline]
278+
fn lt(&self, other: &Cell<T>) -> bool {
279+
self.get() < other.get()
280+
}
281+
282+
#[inline]
283+
fn le(&self, other: &Cell<T>) -> bool {
284+
self.get() <= other.get()
285+
}
286+
287+
#[inline]
288+
fn gt(&self, other: &Cell<T>) -> bool {
289+
self.get() > other.get()
290+
}
291+
292+
#[inline]
293+
fn ge(&self, other: &Cell<T>) -> bool {
294+
self.get() >= other.get()
295+
}
296+
}
297+
298+
#[unstable(feature = "cell_ord", issue = "33305")]
299+
impl<T:Ord + Copy> Ord for Cell<T> {
300+
#[inline]
301+
fn cmp(&self, other: &Cell<T>) -> Ordering {
302+
self.get().cmp(&other.get())
303+
}
304+
}
305+
270306
/// A mutable memory location with dynamically checked borrow rules
271307
///
272308
/// See the [module-level documentation](index.html) for more.
@@ -490,6 +526,42 @@ impl<T: ?Sized + PartialEq> PartialEq for RefCell<T> {
490526
#[stable(feature = "cell_eq", since = "1.2.0")]
491527
impl<T: ?Sized + Eq> Eq for RefCell<T> {}
492528

529+
#[unstable(feature = "cell_ord", issue = "33305")]
530+
impl<T: ?Sized + PartialOrd> PartialOrd for RefCell<T> {
531+
#[inline]
532+
fn partial_cmp(&self, other: &RefCell<T>) -> Option<Ordering> {
533+
self.borrow().partial_cmp(&*other.borrow())
534+
}
535+
536+
#[inline]
537+
fn lt(&self, other: &RefCell<T>) -> bool {
538+
*self.borrow() < *other.borrow()
539+
}
540+
541+
#[inline]
542+
fn le(&self, other: &RefCell<T>) -> bool {
543+
*self.borrow() <= *other.borrow()
544+
}
545+
546+
#[inline]
547+
fn gt(&self, other: &RefCell<T>) -> bool {
548+
*self.borrow() > *other.borrow()
549+
}
550+
551+
#[inline]
552+
fn ge(&self, other: &RefCell<T>) -> bool {
553+
*self.borrow() >= *other.borrow()
554+
}
555+
}
556+
557+
#[unstable(feature = "cell_ord", issue = "33305")]
558+
impl<T: ?Sized + Ord> Ord for RefCell<T> {
559+
#[inline]
560+
fn cmp(&self, other: &RefCell<T>) -> Ordering {
561+
self.borrow().cmp(&*other.borrow())
562+
}
563+
}
564+
493565
struct BorrowRef<'b> {
494566
borrow: &'b Cell<BorrowFlag>,
495567
}

0 commit comments

Comments
 (0)