about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-05-14 22:06:50 -0700
committerbors <bors@rust-lang.org>2014-05-14 22:06:50 -0700
commit73a68cdba0d6e5ee28c9ef1ae80ec473f16cd9e9 (patch)
tree32a053690faa53d61b9b603854f0940e00f6dc57
parente10fd317211511c3fb4656aee10eb4fd17dc8586 (diff)
parent9eb723d00081938ebc6306a7cb73209e45140c95 (diff)
downloadrust-73a68cdba0d6e5ee28c9ef1ae80ec473f16cd9e9.tar.gz
rust-73a68cdba0d6e5ee28c9ef1ae80ec473f16cd9e9.zip
auto merge of #14133 : db48x/rust/ord-for-mut-refs, r=alexcrichton
Also Show, which is useful in assertions. Fixes #14074
-rw-r--r--src/libcore/cmp.rs34
-rw-r--r--src/libstd/fmt/mod.rs3
2 files changed, 36 insertions, 1 deletions
diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs
index f2b1c1cd4cd..52df7e71727 100644
--- a/src/libcore/cmp.rs
+++ b/src/libcore/cmp.rs
@@ -1,4 +1,4 @@
-// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
 // http://rust-lang.org/COPYRIGHT.
 //
@@ -217,6 +217,29 @@ mod impls {
     }
     impl<'a, T: TotalEq> TotalEq for &'a T {}
 
+    // &mut pointers
+    impl<'a, T: Eq> Eq for &'a mut T {
+        #[inline]
+        fn eq(&self, other: &&'a mut T) -> bool { **self == *(*other) }
+        #[inline]
+        fn ne(&self, other: &&'a mut T) -> bool { **self != *(*other) }
+    }
+    impl<'a, T: Ord> Ord for &'a mut T {
+        #[inline]
+        fn lt(&self, other: &&'a mut T) -> bool { **self < **other }
+        #[inline]
+        fn le(&self, other: &&'a mut T) -> bool { **self <= **other }
+        #[inline]
+        fn ge(&self, other: &&'a mut T) -> bool { **self >= **other }
+        #[inline]
+        fn gt(&self, other: &&'a mut T) -> bool { **self > **other }
+    }
+    impl<'a, T: TotalOrd> TotalOrd for &'a mut T {
+        #[inline]
+        fn cmp(&self, other: &&'a mut T) -> Ordering { (**self).cmp(*other) }
+    }
+    impl<'a, T: TotalEq> TotalEq for &'a mut T {}
+
     // @ pointers
     impl<T:Eq> Eq for @T {
         #[inline]
@@ -255,6 +278,15 @@ mod test {
     }
 
     #[test]
+    fn test_mut_int_totalord() {
+        assert_eq!((&mut 5u).cmp(&10), Less);
+        assert_eq!((&mut 10u).cmp(&5), Greater);
+        assert_eq!((&mut 5u).cmp(&5), Equal);
+        assert_eq!((&mut -5u).cmp(&12), Less);
+        assert_eq!((&mut 12u).cmp(-5), Greater);
+    }
+
+    #[test]
     fn test_ordering_order() {
         assert!(Less < Equal);
         assert_eq!(Greater.cmp(&Less), Greater);
diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs
index fecd68e049a..d4f12f590ae 100644
--- a/src/libstd/fmt/mod.rs
+++ b/src/libstd/fmt/mod.rs
@@ -1138,6 +1138,9 @@ impl<T: Show> Show for Box<T> {
 impl<'a, T: Show> Show for &'a T {
     fn fmt(&self, f: &mut Formatter) -> Result { secret_show(*self, f) }
 }
+impl<'a, T: Show> Show for &'a mut T {
+    fn fmt(&self, f: &mut Formatter) -> Result { secret_show(*self, f) }
+}
 
 impl Bool for bool {
     fn fmt(&self, f: &mut Formatter) -> Result {