about summary refs log tree commit diff
path: root/src/libstd/cmp.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-03-23 08:36:51 -0700
committerbors <bors@rust-lang.org>2014-03-23 08:36:51 -0700
commit903e83889ade166bf62f1ee74df8bf8331ea17d1 (patch)
tree2d2c838f7adc52628632948a8b37820c4f03ed75 /src/libstd/cmp.rs
parentcafb7ed6f671a0102c4df9abad43b747c00f5cdf (diff)
parentf6db0ef9464a17fa6e547e755b1b5dfa09af9499 (diff)
downloadrust-903e83889ade166bf62f1ee74df8bf8331ea17d1.tar.gz
rust-903e83889ade166bf62f1ee74df8bf8331ea17d1.zip
auto merge of #13102 : huonw/rust/totaleq-deriving, r=thestinger
std: remove the `equals` method from `TotalEq`.

`TotalEq` is now just an assertion about the `Eq` impl of a
type (i.e. `==` is a total equality if a type implements `TotalEq`) so
the extra method is just confusing.

Also, a new method magically appeared as a hack to allow deriving to
assert that the contents of a struct/enum are also TotalEq, because the
deriving infrastructure makes it very hard to do anything but create a
trait method. (You didn't hear about this horrible work-around from me
:(.)
Diffstat (limited to 'src/libstd/cmp.rs')
-rw-r--r--src/libstd/cmp.rs33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/libstd/cmp.rs b/src/libstd/cmp.rs
index 5130da44ed5..e956a1cdf1d 100644
--- a/src/libstd/cmp.rs
+++ b/src/libstd/cmp.rs
@@ -42,6 +42,21 @@ pub trait Eq {
 }
 
 /// Trait for equality comparisons where `a == b` and `a != b` are strict inverses.
+#[cfg(not(stage0))]
+pub trait TotalEq: Eq {
+    // FIXME #13101: this method is used solely by #[deriving] to
+    // assert that every component of a type implements #[deriving]
+    // itself, the current deriving infrastructure means doing this
+    // assertion without using a method on this trait is nearly
+    // impossible.
+    //
+    // This should never be implemented by hand.
+    #[doc(hidden)]
+    #[inline(always)]
+    fn assert_receiver_is_total_eq(&self) {}
+}
+
+#[cfg(stage0)]
 pub trait TotalEq: Eq {
     /// This method must return the same value as `eq`. It exists to prevent
     /// deriving `TotalEq` from fields not implementing the `TotalEq` trait.
@@ -52,10 +67,7 @@ pub trait TotalEq: Eq {
 
 macro_rules! totaleq_impl(
     ($t:ty) => {
-        impl TotalEq for $t {
-            #[inline]
-            fn equals(&self, other: &$t) -> bool { *self == *other }
-        }
+        impl TotalEq for $t {}
     }
 )
 
@@ -84,12 +96,7 @@ pub trait TotalOrd: TotalEq + Ord {
     fn cmp(&self, other: &Self) -> Ordering;
 }
 
-impl TotalEq for Ordering {
-    #[inline]
-    fn equals(&self, other: &Ordering) -> bool {
-        *self == *other
-    }
-}
+impl TotalEq for Ordering {}
 impl TotalOrd for Ordering {
     #[inline]
     fn cmp(&self, other: &Ordering) -> Ordering {
@@ -195,12 +202,6 @@ mod test {
     }
 
     #[test]
-    fn test_int_totaleq() {
-        assert!(5.equals(&5));
-        assert!(!2.equals(&17));
-    }
-
-    #[test]
     fn test_ordering_order() {
         assert!(Less < Equal);
         assert_eq!(Greater.cmp(&Less), Greater);