about summary refs log tree commit diff
path: root/src/libnum
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/libnum
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/libnum')
-rw-r--r--src/libnum/bigint.rs41
-rw-r--r--src/libnum/rational.rs6
2 files changed, 9 insertions, 38 deletions
diff --git a/src/libnum/bigint.rs b/src/libnum/bigint.rs
index 5716a1dedf3..89ad2b5d1bc 100644
--- a/src/libnum/bigint.rs
+++ b/src/libnum/bigint.rs
@@ -92,15 +92,11 @@ pub struct BigUint {
 
 impl Eq for BigUint {
     #[inline]
-    fn eq(&self, other: &BigUint) -> bool { self.equals(other) }
-}
-
-impl TotalEq for BigUint {
-    #[inline]
-    fn equals(&self, other: &BigUint) -> bool {
+    fn eq(&self, other: &BigUint) -> bool {
         match self.cmp(other) { Equal => true, _ => false }
     }
 }
+impl TotalEq for BigUint {}
 
 impl Ord for BigUint {
     #[inline]
@@ -852,31 +848,9 @@ fn get_radix_base(radix: uint) -> (uint, uint) {
 }
 
 /// A Sign is a `BigInt`'s composing element.
-#[deriving(Eq, Clone, Show)]
+#[deriving(Eq, Ord, TotalEq, TotalOrd, Clone, Show)]
 pub enum Sign { Minus, Zero, Plus }
 
-impl Ord for Sign {
-    #[inline]
-    fn lt(&self, other: &Sign) -> bool {
-        match self.cmp(other) { Less => true, _ => false}
-    }
-}
-
-impl TotalEq for Sign {
-    #[inline]
-    fn equals(&self, other: &Sign) -> bool { *self == *other }
-}
-impl TotalOrd for Sign {
-    #[inline]
-    fn cmp(&self, other: &Sign) -> Ordering {
-        match (*self, *other) {
-          (Minus, Minus) | (Zero,  Zero) | (Plus, Plus) => Equal,
-          (Minus, Zero)  | (Minus, Plus) | (Zero, Plus) => Less,
-          _                                             => Greater
-        }
-    }
-}
-
 impl Neg<Sign> for Sign {
     /// Negate Sign value.
     #[inline]
@@ -898,16 +872,13 @@ pub struct BigInt {
 
 impl Eq for BigInt {
     #[inline]
-    fn eq(&self, other: &BigInt) -> bool { self.equals(other) }
-}
-
-impl TotalEq for BigInt {
-    #[inline]
-    fn equals(&self, other: &BigInt) -> bool {
+    fn eq(&self, other: &BigInt) -> bool {
         match self.cmp(other) { Equal => true, _ => false }
     }
 }
 
+impl TotalEq for BigInt {}
+
 impl Ord for BigInt {
     #[inline]
     fn lt(&self, other: &BigInt) -> bool {
diff --git a/src/libnum/rational.rs b/src/libnum/rational.rs
index a71674c4122..6fb3d492432 100644
--- a/src/libnum/rational.rs
+++ b/src/libnum/rational.rs
@@ -147,20 +147,20 @@ macro_rules! cmp_impl {
         cmp_impl!(impl $imp, $($method -> bool),+)
     };
     // return something other than a Ratio<T>
-    (impl $imp:ident, $($method:ident -> $res:ty),+) => {
+    (impl $imp:ident, $($method:ident -> $res:ty),*) => {
         impl<T: Mul<T,T> + $imp> $imp for Ratio<T> {
             $(
                 #[inline]
                 fn $method(&self, other: &Ratio<T>) -> $res {
                     (self.numer * other.denom). $method (&(self.denom*other.numer))
                 }
-            )+
+            )*
         }
     };
 }
 cmp_impl!(impl Eq, eq, ne)
-cmp_impl!(impl TotalEq, equals)
 cmp_impl!(impl Ord, lt, gt, le, ge)
+cmp_impl!(impl TotalEq, )
 cmp_impl!(impl TotalOrd, cmp -> cmp::Ordering)
 
 /* Arithmetic */