about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-12-11 15:16:36 -0800
committerBrian Anderson <banderson@mozilla.com>2012-12-13 16:14:28 -0800
commitd809e89c2682c3bb0ec0b58d7a8beb71060ae619 (patch)
tree3e31eb1e518adf5f6c27dab2390b2973e95c7b6e
parent742f354ffb08d81f6977aabc78a854cced22b9d3 (diff)
downloadrust-d809e89c2682c3bb0ec0b58d7a8beb71060ae619.tar.gz
rust-d809e89c2682c3bb0ec0b58d7a8beb71060ae619.zip
Replace some Eq impls with deriving_eq
-rw-r--r--src/libcore/core.rc2
-rw-r--r--src/libcore/either.rs21
-rw-r--r--src/libcore/extfmt.rs17
-rw-r--r--src/libcore/io.rs11
-rw-r--r--src/libcore/option.rs22
-rw-r--r--src/libcore/path.rs20
-rw-r--r--src/libcore/repr.rs8
-rw-r--r--src/libcore/result.rs21
-rw-r--r--src/libcore/task/mod.rs1
-rw-r--r--src/libstd/getopts.rs125
-rw-r--r--src/libstd/list.rs21
-rw-r--r--src/libstd/test.rs8
-rw-r--r--src/libstd/workcache.rs10
13 files changed, 24 insertions, 263 deletions
diff --git a/src/libcore/core.rc b/src/libcore/core.rc
index a30567639a9..eb7d753ea08 100644
--- a/src/libcore/core.rc
+++ b/src/libcore/core.rc
@@ -240,6 +240,8 @@ mod core {
     pub const warn : u32 = 2_u32;
     pub const info : u32 = 3_u32;
     pub const debug : u32 = 4_u32;
+
+    pub use cmp;
 }
 
 
diff --git a/src/libcore/either.rs b/src/libcore/either.rs
index 878fd81651a..74b29f3a5f1 100644
--- a/src/libcore/either.rs
+++ b/src/libcore/either.rs
@@ -18,6 +18,7 @@ use cmp::Eq;
 use result::Result;
 
 /// The either type
+#[deriving_eq]
 pub enum Either<T, U> {
     Left(T),
     Right(U)
@@ -141,26 +142,6 @@ pub pure fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
     }
 }
 
-impl<T:Eq,U:Eq> Either<T,U> : Eq {
-    pure fn eq(&self, other: &Either<T,U>) -> bool {
-        match (*self) {
-            Left(ref a) => {
-                match (*other) {
-                    Left(ref b) => (*a).eq(b),
-                    Right(_) => false
-                }
-            }
-            Right(ref a) => {
-                match (*other) {
-                    Left(_) => false,
-                    Right(ref b) => (*a).eq(b)
-                }
-            }
-        }
-    }
-    pure fn ne(&self, other: &Either<T,U>) -> bool { !(*self).eq(other) }
-}
-
 #[test]
 fn test_either_left() {
     let val = Left(10);
diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs
index aedc24d3ce9..1c9ad6ba81a 100644
--- a/src/libcore/extfmt.rs
+++ b/src/libcore/extfmt.rs
@@ -445,24 +445,9 @@ pub mod rt {
             };
     }
 
+    #[deriving_eq]
     pub enum PadMode { PadSigned, PadUnsigned, PadNozero, PadFloat }
 
-    pub impl PadMode : Eq {
-        pure fn eq(&self, other: &PadMode) -> bool {
-            match ((*self), (*other)) {
-                (PadSigned, PadSigned) => true,
-                (PadUnsigned, PadUnsigned) => true,
-                (PadNozero, PadNozero) => true,
-                (PadFloat, PadFloat) => true,
-                (PadSigned, _) => false,
-                (PadUnsigned, _) => false,
-                (PadNozero, _) => false,
-                (PadFloat, _) => false
-            }
-        }
-        pure fn ne(&self, other: &PadMode) -> bool { !(*self).eq(other) }
-    }
-
     pub fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str {
         let mut s = move s; // sadtimes
         let uwidth : uint = match cv.width {
diff --git a/src/libcore/io.rs b/src/libcore/io.rs
index 424620271a2..098e24e03dd 100644
--- a/src/libcore/io.rs
+++ b/src/libcore/io.rs
@@ -523,18 +523,9 @@ pub pure fn with_str_reader<T>(s: &str, f: fn(Reader) -> T) -> T {
 pub enum FileFlag { Append, Create, Truncate, NoFlag, }
 
 // What type of writer are we?
+#[deriving_eq]
 pub enum WriterType { Screen, File }
 
-pub impl WriterType : Eq {
-    pure fn eq(&self, other: &WriterType) -> bool {
-        match ((*self), (*other)) {
-            (Screen, Screen) | (File, File) => true,
-            (Screen, _) | (File, _) => false
-        }
-    }
-    pure fn ne(&self, other: &WriterType) -> bool { !(*self).eq(other) }
-}
-
 // FIXME (#2004): Seekable really should be orthogonal.
 // FIXME (#2004): eventually u64
 /// The raw underlying writer trait. All writers must implement this.
diff --git a/src/libcore/option.rs b/src/libcore/option.rs
index 09e35b1037b..f7de25bf021 100644
--- a/src/libcore/option.rs
+++ b/src/libcore/option.rs
@@ -47,6 +47,7 @@ let unwrapped_msg = match move msg {
 use cmp::Eq;
 
 /// The option type
+#[deriving_eq]
 pub enum Option<T> {
     None,
     Some(T),
@@ -310,27 +311,6 @@ impl<T: Copy> Option<T> {
     pure fn while_some(blk: fn(v: T) -> Option<T>) { while_some(self, blk) }
 }
 
-impl<T: Eq> Option<T> : Eq {
-    pure fn eq(&self, other: &Option<T>) -> bool {
-        match (*self) {
-            None => {
-                match (*other) {
-                    None => true,
-                    Some(_) => false
-                }
-            }
-            Some(ref self_contents) => {
-                match (*other) {
-                    None => false,
-                    Some(ref other_contents) =>
-                        (*self_contents).eq(other_contents)
-                }
-            }
-        }
-    }
-    pure fn ne(&self, other: &Option<T>) -> bool { !(*self).eq(other) }
-}
-
 #[test]
 fn test_unwrap_ptr() {
     let x = ~0;
diff --git a/src/libcore/path.rs b/src/libcore/path.rs
index 0fd30501a4c..cdd66364c11 100644
--- a/src/libcore/path.rs
+++ b/src/libcore/path.rs
@@ -20,6 +20,7 @@ Cross-platform file path handling
 
 use cmp::Eq;
 
+#[deriving_eq]
 pub struct WindowsPath {
     host: Option<~str>,
     device: Option<~str>,
@@ -31,6 +32,7 @@ pub pure fn WindowsPath(s: &str) -> WindowsPath {
     from_str(s)
 }
 
+#[deriving_eq]
 pub struct PosixPath {
     is_absolute: bool,
     components: ~[~str],
@@ -356,24 +358,6 @@ impl PosixPath : ToStr {
     }
 }
 
-impl PosixPath : Eq {
-    pure fn eq(&self, other: &PosixPath) -> bool {
-        return (*self).is_absolute == (*other).is_absolute &&
-            (*self).components == (*other).components;
-    }
-    pure fn ne(&self, other: &PosixPath) -> bool { !(*self).eq(other) }
-}
-
-impl WindowsPath : Eq {
-    pure fn eq(&self, other: &WindowsPath) -> bool {
-        return (*self).host == (*other).host &&
-            (*self).device == (*other).device &&
-            (*self).is_absolute == (*other).is_absolute &&
-            (*self).components == (*other).components;
-    }
-    pure fn ne(&self, other: &WindowsPath) -> bool { !(*self).eq(other) }
-}
-
 // FIXME (#3227): when default methods in traits are working, de-duplicate
 // PosixPath and WindowsPath, most of their methods are common.
 impl PosixPath : GenericPath {
diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs
index 9a0cfeefd60..46bef4dd68a 100644
--- a/src/libcore/repr.rs
+++ b/src/libcore/repr.rs
@@ -518,6 +518,7 @@ fn test_repr2() {
 
 // Old non-factored implementation, transitional...
 
+#[deriving_eq]
 enum EnumVisitState {
     PreVariant,     // We're before the variant we're interested in.
     InVariant,      // We're inside the variant we're interested in.
@@ -525,13 +526,6 @@ enum EnumVisitState {
     Degenerate      // This is a degenerate enum (exactly 1 variant)
 }
 
-impl EnumVisitState : cmp::Eq {
-    pure fn eq(&self, other: &EnumVisitState) -> bool {
-        ((*self) as uint) == ((*other) as uint)
-    }
-    pure fn ne(&self, other: &EnumVisitState) -> bool { !(*self).eq(other) }
-}
-
 struct EnumState {
     end_ptr: *c_void,
     state: EnumVisitState
diff --git a/src/libcore/result.rs b/src/libcore/result.rs
index d575655f7a5..a1e7df28872 100644
--- a/src/libcore/result.rs
+++ b/src/libcore/result.rs
@@ -19,6 +19,7 @@ use cmp::Eq;
 use either::Either;
 
 /// The result type
+#[deriving_eq]
 pub enum Result<T, U> {
     /// Contains the successful result value
     Ok(T),
@@ -374,26 +375,6 @@ pub fn unwrap_err<T, U>(res: Result<T, U>) -> U {
     }
 }
 
-impl<T:Eq,U:Eq> Result<T,U> : Eq {
-    pure fn eq(&self, other: &Result<T,U>) -> bool {
-        match (*self) {
-            Ok(ref e0a) => {
-                match (*other) {
-                    Ok(ref e0b) => *e0a == *e0b,
-                    _ => false
-                }
-            }
-            Err(ref e0a) => {
-                match (*other) {
-                    Err(ref e0b) => *e0a == *e0b,
-                    _ => false
-                }
-            }
-        }
-    }
-    pure fn ne(&self, other: &Result<T,U>) -> bool { !(*self).eq(other) }
-}
-
 #[cfg(test)]
 #[allow(non_implicitly_copyable_typarams)]
 mod tests {
diff --git a/src/libcore/task/mod.rs b/src/libcore/task/mod.rs
index 1ba2c1dc2c1..6db7aae16b0 100644
--- a/src/libcore/task/mod.rs
+++ b/src/libcore/task/mod.rs
@@ -55,6 +55,7 @@ pub enum Task {
     TaskHandle(task_id)
 }
 
+// XXX: deriving
 impl Task : cmp::Eq {
     pure fn eq(&self, other: &Task) -> bool { *(*self) == *(*other) }
     pure fn ne(&self, other: &Task) -> bool { !(*self).eq(other) }
diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs
index e7851b3ecb9..38540524dac 100644
--- a/src/libstd/getopts.rs
+++ b/src/libstd/getopts.rs
@@ -79,16 +79,20 @@ use core::result::{Err, Ok};
 use core::option;
 use core::option::{Some, None};
 
+#[deriving_eq]
 enum Name {
     Long(~str),
     Short(char),
 }
 
+#[deriving_eq]
 enum HasArg { Yes, No, Maybe, }
 
+#[deriving_eq]
 enum Occur { Req, Optional, Multi, }
 
 /// A description of a possible option
+#[deriving_eq]
 pub struct Opt {
     name: Name,
     hasarg: HasArg,
@@ -102,49 +106,6 @@ fn mkname(nm: &str) -> Name {
         } else { Long(unm) };
 }
 
-impl Name : Eq {
-    pure fn eq(&self, other: &Name) -> bool {
-        match (*self) {
-            Long(ref e0a) => {
-                match (*other) {
-                    Long(ref e0b) => e0a == e0b,
-                    _ => false
-                }
-            }
-            Short(e0a) => {
-                match (*other) {
-                    Short(e0b) => e0a == e0b,
-                    _ => false
-                }
-            }
-        }
-    }
-    pure fn ne(&self, other: &Name) -> bool { !(*self).eq(other) }
-}
-
-impl Occur : Eq {
-    pure fn eq(&self, other: &Occur) -> bool {
-        ((*self) as uint) == ((*other) as uint)
-    }
-    pure fn ne(&self, other: &Occur) -> bool { !(*self).eq(other) }
-}
-
-impl HasArg : Eq {
-    pure fn eq(&self, other: &HasArg) -> bool {
-        ((*self) as uint) == ((*other) as uint)
-    }
-    pure fn ne(&self, other: &HasArg) -> bool { !(*self).eq(other) }
-}
-
-impl Opt : Eq {
-    pure fn eq(&self, other: &Opt) -> bool {
-        (*self).name   == (*other).name   &&
-        (*self).hasarg == (*other).hasarg &&
-        (*self).occur  == (*other).occur
-    }
-    pure fn ne(&self, other: &Opt) -> bool { !(*self).eq(other) }
-}
-
 /// Create an option that is required and takes an argument
 pub fn reqopt(name: &str) -> Opt {
     return Opt {name: mkname(name), hasarg: Yes, occur: Req};
@@ -178,39 +139,20 @@ pub fn optmulti(name: &str) -> Opt {
     return Opt {name: mkname(name), hasarg: Yes, occur: Multi};
 }
 
+#[deriving_eq]
 enum Optval { Val(~str), Given, }
 
 /**
  * The result of checking command line arguments. Contains a vector
  * of matches and a vector of free strings.
  */
+#[deriving_eq]
 pub struct Matches {
     opts: ~[Opt],
     vals: ~[~[Optval]],
     free: ~[~str]
 }
 
-impl Optval : Eq {
-    pure fn eq(&self, other: &Optval) -> bool {
-        match (*self) {
-            Val(ref s) => match *other { Val (ref os) => s == os,
-                                          Given => false },
-            Given       => match *other { Val(_) => false,
-                                          Given => true }
-        }
-    }
-    pure fn ne(&self, other: &Optval) -> bool { !(*self).eq(other) }
-}
-
-impl Matches : Eq {
-    pure fn eq(&self, other: &Matches) -> bool {
-        (*self).opts == (*other).opts &&
-        (*self).vals == (*other).vals &&
-        (*self).free == (*other).free
-    }
-    pure fn ne(&self, other: &Matches) -> bool { !(*self).eq(other) }
-}
-
 fn is_arg(arg: &str) -> bool {
     return arg.len() > 1 && arg[0] == '-' as u8;
 }
@@ -230,6 +172,7 @@ fn find_opt(opts: &[Opt], nm: Name) -> Option<uint> {
  * The type returned when the command line does not conform to the
  * expected format. Pass this value to <fail_str> to get an error message.
  */
+#[deriving_eq]
 pub enum Fail_ {
     ArgumentMissing(~str),
     UnrecognizedOption(~str),
@@ -238,35 +181,6 @@ pub enum Fail_ {
     UnexpectedArgument(~str),
 }
 
-impl Fail_ : Eq {
-    // this whole thing should be easy to infer...
-    pure fn eq(&self, other: &Fail_) -> bool {
-        match (*self) {
-            ArgumentMissing(ref s) => {
-                match *other { ArgumentMissing(ref so)    => s == so,
-                               _                          => false }
-            }
-            UnrecognizedOption(ref s) => {
-                match *other { UnrecognizedOption(ref so) => s == so,
-                               _                          => false }
-            }
-            OptionMissing(ref s) => {
-                match *other { OptionMissing(ref so)      => s == so,
-                               _                          => false }
-            }
-            OptionDuplicated(ref s) => {
-                match *other { OptionDuplicated(ref so)   => s == so,
-                               _                          => false }
-            }
-            UnexpectedArgument(ref s) => {
-                match *other { UnexpectedArgument(ref so) => s == so,
-                               _                          => false }
-            }
-        }
-    }
-    pure fn ne(&self, other: &Fail_) -> bool { !(*self).eq(other) }
-}
-
 /// Convert a `fail_` enum into an error string
 pub fn fail_str(f: Fail_) -> ~str {
     return match f {
@@ -523,6 +437,7 @@ pub fn opt_default(mm: &Matches, nm: &str, def: &str) -> Option<~str> {
                            _      => Some::<~str>(str::from_slice(def)) }
 }
 
+#[deriving_eq]
 enum FailType {
     ArgumentMissing_,
     UnrecognizedOption_,
@@ -531,13 +446,6 @@ enum FailType {
     UnexpectedArgument_,
 }
 
-impl FailType : Eq {
-    pure fn eq(&self, other: &FailType) -> bool {
-        ((*self) as uint) == ((*other) as uint)
-    }
-    pure fn ne(&self, other: &FailType) -> bool { !(*self).eq(other) }
-}
-
 /** A module which provides a way to specify descriptions and
  *  groups of short and long option names, together.
  */
@@ -546,6 +454,7 @@ pub mod groups {
     /** one group of options, e.g., both -h and --help, along with
      * their shared description and properties
      */
+    #[deriving_eq]
     pub struct OptGroup {
         short_name: ~str,
         long_name: ~str,
@@ -555,20 +464,6 @@ pub mod groups {
         occur: Occur
     }
 
-    impl OptGroup : Eq {
-        pure fn eq(&self, other: &OptGroup) -> bool {
-            (*self).short_name == (*other).short_name &&
-            (*self).long_name  == (*other).long_name  &&
-            (*self).hint       == (*other).hint       &&
-            (*self).desc       == (*other).desc       &&
-            (*self).hasarg     == (*other).hasarg     &&
-            (*self).occur      == (*other).occur
-        }
-        pure fn ne(&self, other: &OptGroup) -> bool {
-            !self.eq(other)
-        }
-    }
-
     /// Create a long option that is required and takes an argument
     pub fn reqopt(short_name: &str, long_name: &str,
                   desc: &str, hint: &str) -> OptGroup {
@@ -733,7 +628,7 @@ mod tests {
     #[legacy_exports];
     use opt = getopts;
     use result::{Err, Ok};
-    use opt::groups::OptGroup;
+    use getopts::groups::OptGroup;
 
     fn check_fail_type(f: Fail_, ft: FailType) {
         match f {
diff --git a/src/libstd/list.rs b/src/libstd/list.rs
index 68f807f8403..6d2c10eb827 100644
--- a/src/libstd/list.rs
+++ b/src/libstd/list.rs
@@ -16,6 +16,7 @@ use core::option;
 use option::*;
 use option::{Some, None};
 
+#[deriving_eq]
 pub enum List<T> {
     Cons(T, @List<T>),
     Nil,
@@ -157,26 +158,6 @@ pub fn each<T>(l: @List<T>, f: fn(&T) -> bool) {
     }
 }
 
-impl<T:Eq> List<T> : Eq {
-    pure fn eq(&self, other: &List<T>) -> bool {
-        match (*self) {
-            Cons(ref e0a, e1a) => {
-                match (*other) {
-                    Cons(ref e0b, e1b) => e0a == e0b && e1a == e1b,
-                    _ => false
-                }
-            }
-            Nil => {
-                match (*other) {
-                    Nil => true,
-                    _ => false
-                }
-            }
-        }
-    }
-    pure fn ne(&self, other: &List<T>) -> bool { !(*self).eq(other) }
-}
-
 #[cfg(test)]
 mod tests {
     #[legacy_exports];
diff --git a/src/libstd/test.rs b/src/libstd/test.rs
index b2dcf02a569..2bf735dd584 100644
--- a/src/libstd/test.rs
+++ b/src/libstd/test.rs
@@ -92,15 +92,9 @@ fn parse_opts(args: &[~str]) -> OptRes {
     return either::Left(test_opts);
 }
 
+#[deriving_eq]
 pub enum TestResult { TrOk, TrFailed, TrIgnored, }
 
-impl TestResult : Eq {
-    pure fn eq(&self, other: &TestResult) -> bool {
-        ((*self) as uint) == ((*other) as uint)
-    }
-    pure fn ne(&self, other: &TestResult) -> bool { !(*self).eq(other) }
-}
-
 type ConsoleTestState =
     @{out: io::Writer,
       log_out: Option<io::Writer>,
diff --git a/src/libstd/workcache.rs b/src/libstd/workcache.rs
index 8b394443170..71151c33060 100644
--- a/src/libstd/workcache.rs
+++ b/src/libstd/workcache.rs
@@ -79,6 +79,7 @@ use serialization::{Serializer,Serializable,
 *
 */
 
+#[deriving_eq]
 struct WorkKey {
     kind: ~str,
     name: ~str
@@ -100,15 +101,6 @@ impl WorkKey {
     }
 }
 
-impl WorkKey: core::cmp::Eq {
-    pure fn eq(&self, other: &WorkKey) -> bool {
-        self.kind == other.kind && self.name == other.name
-    }
-    pure fn ne(&self, other: &WorkKey) -> bool {
-        self.kind != other.kind || self.name != other.name
-    }
-}
-
 type WorkMap = LinearMap<WorkKey, ~str>;
 
 struct Database {