about summary refs log tree commit diff
path: root/src/libstd
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
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')
-rw-r--r--src/libstd/cmp.rs33
-rw-r--r--src/libstd/iter.rs4
-rw-r--r--src/libstd/managed.rs5
-rw-r--r--src/libstd/owned.rs5
-rw-r--r--src/libstd/reference.rs6
-rw-r--r--src/libstd/slice.rs12
-rw-r--r--src/libstd/str.rs27
-rw-r--r--src/libstd/tuple.rs13
-rw-r--r--src/libstd/unit.rs5
-rw-r--r--src/libstd/vec.rs7
10 files changed, 32 insertions, 85 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);
diff --git a/src/libstd/iter.rs b/src/libstd/iter.rs
index ead26fb920c..8762f23c3ce 100644
--- a/src/libstd/iter.rs
+++ b/src/libstd/iter.rs
@@ -2180,13 +2180,13 @@ pub mod order {
     use option::{Some, None};
     use super::Iterator;
 
-    /// Compare `a` and `b` for equality using `TotalOrd`
+    /// Compare `a` and `b` for equality using `TotalEq`
     pub fn equals<A: TotalEq, T: Iterator<A>>(mut a: T, mut b: T) -> bool {
         loop {
             match (a.next(), b.next()) {
                 (None, None) => return true,
                 (None, _) | (_, None) => return false,
-                (Some(x), Some(y)) => if !x.equals(&y) { return false },
+                (Some(x), Some(y)) => if x != y { return false },
             }
         }
     }
diff --git a/src/libstd/managed.rs b/src/libstd/managed.rs
index 141ed7a9206..bf73c05440c 100644
--- a/src/libstd/managed.rs
+++ b/src/libstd/managed.rs
@@ -45,10 +45,7 @@ impl<T: TotalOrd> TotalOrd for @T {
 }
 
 #[cfg(not(test))]
-impl<T: TotalEq> TotalEq for @T {
-    #[inline]
-    fn equals(&self, other: &@T) -> bool { (**self).equals(*other) }
-}
+impl<T: TotalEq> TotalEq for @T {}
 
 #[test]
 fn test() {
diff --git a/src/libstd/owned.rs b/src/libstd/owned.rs
index dc8ea34c84b..1fa86c53117 100644
--- a/src/libstd/owned.rs
+++ b/src/libstd/owned.rs
@@ -53,7 +53,4 @@ impl<T: TotalOrd> TotalOrd for ~T {
 }
 
 #[cfg(not(test))]
-impl<T: TotalEq> TotalEq for ~T {
-    #[inline]
-    fn equals(&self, other: &~T) -> bool { (**self).equals(*other) }
-}
+impl<T: TotalEq> TotalEq for ~T {}
diff --git a/src/libstd/reference.rs b/src/libstd/reference.rs
index fdbca2b9f33..eb615afd85f 100644
--- a/src/libstd/reference.rs
+++ b/src/libstd/reference.rs
@@ -54,8 +54,4 @@ impl<'a, T: TotalOrd> TotalOrd for &'a T {
 }
 
 #[cfg(not(test))]
-impl<'a, T: TotalEq> TotalEq for &'a T {
-    #[inline]
-    fn equals(&self, other: & &'a T) -> bool { (**self).equals(*other) }
-}
-
+impl<'a, T: TotalEq> TotalEq for &'a T {}
diff --git a/src/libstd/slice.rs b/src/libstd/slice.rs
index 83f2299ad7b..985feaf6ab6 100644
--- a/src/libstd/slice.rs
+++ b/src/libstd/slice.rs
@@ -649,17 +649,9 @@ pub mod traits {
         fn ne(&self, other: &~[T]) -> bool { !self.eq(other) }
     }
 
-    impl<'a,T:TotalEq> TotalEq for &'a [T] {
-        fn equals(&self, other: & &'a [T]) -> bool {
-            self.len() == other.len() &&
-                order::equals(self.iter(), other.iter())
-        }
-    }
+    impl<'a,T:TotalEq> TotalEq for &'a [T] {}
 
-    impl<T:TotalEq> TotalEq for ~[T] {
-        #[inline]
-        fn equals(&self, other: &~[T]) -> bool { self.as_slice().equals(&other.as_slice()) }
-    }
+    impl<T:TotalEq> TotalEq for ~[T] {}
 
     impl<'a,T:Eq, V: Vector<T>> Equiv<V> for &'a [T] {
         #[inline]
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index 6a3b4485a24..4466439bcbd 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -1262,16 +1262,11 @@ impl<'a> IntoMaybeOwned<'a> for MaybeOwned<'a> {
 impl<'a> Eq for MaybeOwned<'a> {
     #[inline]
     fn eq(&self, other: &MaybeOwned) -> bool {
-        self.as_slice().equals(&other.as_slice())
+        self.as_slice() == other.as_slice()
     }
 }
 
-impl<'a> TotalEq for MaybeOwned<'a> {
-    #[inline]
-    fn equals(&self, other: &MaybeOwned) -> bool {
-        self.as_slice().equals(&other.as_slice())
-    }
-}
+impl<'a> TotalEq for MaybeOwned<'a> {}
 
 impl<'a> Ord for MaybeOwned<'a> {
     #[inline]
@@ -1290,7 +1285,7 @@ impl<'a> TotalOrd for MaybeOwned<'a> {
 impl<'a, S: Str> Equiv<S> for MaybeOwned<'a> {
     #[inline]
     fn equiv(&self, other: &S) -> bool {
-        self.as_slice().equals(&other.as_slice())
+        self.as_slice() == other.as_slice()
     }
 }
 
@@ -1577,19 +1572,9 @@ pub mod traits {
         }
     }
 
-    impl<'a> TotalEq for &'a str {
-        #[inline]
-        fn equals(&self, other: & &'a str) -> bool {
-            eq_slice((*self), (*other))
-        }
-    }
+    impl<'a> TotalEq for &'a str {}
 
-    impl TotalEq for ~str {
-        #[inline]
-        fn equals(&self, other: &~str) -> bool {
-            eq_slice((*self), (*other))
-        }
-    }
+    impl TotalEq for ~str {}
 
     impl<'a> Ord for &'a str {
         #[inline]
@@ -4450,11 +4435,9 @@ mod tests {
         assert_eq!(Owned(~""), Default::default());
 
         assert!(s.cmp(&o) == Equal);
-        assert!(s.equals(&o));
         assert!(s.equiv(&o));
 
         assert!(o.cmp(&s) == Equal);
-        assert!(o.equals(&s));
         assert!(o.equiv(&s));
     }
 
diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs
index e9125dde011..c4ce6b5ae66 100644
--- a/src/libstd/tuple.rs
+++ b/src/libstd/tuple.rs
@@ -75,12 +75,7 @@ macro_rules! tuple_impls {
             }
 
             #[cfg(not(test))]
-            impl<$($T:TotalEq),+> TotalEq for ($($T,)+) {
-                #[inline]
-                fn equals(&self, other: &($($T,)+)) -> bool {
-                    $(self.$refN().equals(other.$refN()))&&+
-                }
-            }
+            impl<$($T:TotalEq),+> TotalEq for ($($T,)+) {}
 
             #[cfg(not(test))]
             impl<$($T:Ord + Eq),+> Ord for ($($T,)+) {
@@ -338,12 +333,6 @@ mod tests {
         assert!(((1.0, 2.0) < (2.0, nan)));
         assert!(!((2.0, 2.0) < (2.0, nan)));
 
-        // TotalEq
-        assert!(small.equals(&small));
-        assert!(big.equals(&big));
-        assert!(!small.equals(&big));
-        assert!(!big.equals(&small));
-
         // TotalOrd
         assert!(small.cmp(&small) == Equal);
         assert!(big.cmp(&big) == Equal);
diff --git a/src/libstd/unit.rs b/src/libstd/unit.rs
index b23dafbca69..38307f415ac 100644
--- a/src/libstd/unit.rs
+++ b/src/libstd/unit.rs
@@ -37,10 +37,7 @@ impl TotalOrd for () {
 }
 
 #[cfg(not(test))]
-impl TotalEq for () {
-    #[inline]
-    fn equals(&self, _other: &()) -> bool { true }
-}
+impl TotalEq for () {}
 
 #[cfg(not(test))]
 impl Default for () {
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index c1f5dea91d1..d00a411e9a0 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -339,12 +339,7 @@ impl<T: Ord> Ord for Vec<T> {
     }
 }
 
-impl<T: TotalEq> TotalEq for Vec<T> {
-    #[inline]
-    fn equals(&self, other: &Vec<T>) -> bool {
-        self.as_slice().equals(&other.as_slice())
-    }
-}
+impl<T: TotalEq> TotalEq for Vec<T> {}
 
 impl<T: TotalOrd> TotalOrd for Vec<T> {
     #[inline]