]> git.lizzy.rs Git - rust.git/commitdiff
auto merge of #14133 : db48x/rust/ord-for-mut-refs, r=alexcrichton
authorbors <bors@rust-lang.org>
Thu, 15 May 2014 05:06:50 +0000 (22:06 -0700)
committerbors <bors@rust-lang.org>
Thu, 15 May 2014 05:06:50 +0000 (22:06 -0700)
Also Show, which is useful in assertions. Fixes #14074

src/libcore/cmp.rs
src/libstd/fmt/mod.rs

index f2b1c1cd4cde699af5d80a13f3c799b219536e38..52df7e71727ee2c8baa2b4216c2a6e22237be612 100644 (file)
@@ -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 @@ fn cmp(&self, other: & &'a T) -> Ordering { (**self).cmp(*other) }
     }
     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]
@@ -254,6 +277,15 @@ fn test_int_totalord() {
         assert_eq!(12u.cmp(-5), Greater);
     }
 
+    #[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);
index fecd68e049a6f315d77499d54bf648f42476a1ea..d4f12f590ae7516c0e064c2c7395f471d44facd1 100644 (file)
@@ -1138,6 +1138,9 @@ fn fmt(&self, f: &mut Formatter) -> Result { secret_show(&**self, f) }
 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 {