diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-12-11 15:16:36 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-12-13 16:14:28 -0800 |
| commit | d809e89c2682c3bb0ec0b58d7a8beb71060ae619 (patch) | |
| tree | 3e31eb1e518adf5f6c27dab2390b2973e95c7b6e /src/libcore | |
| parent | 742f354ffb08d81f6977aabc78a854cced22b9d3 (diff) | |
Replace some Eq impls with deriving_eq
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/core.rc | 2 | ||||
| -rw-r--r-- | src/libcore/either.rs | 21 | ||||
| -rw-r--r-- | src/libcore/extfmt.rs | 17 | ||||
| -rw-r--r-- | src/libcore/io.rs | 11 | ||||
| -rw-r--r-- | src/libcore/option.rs | 22 | ||||
| -rw-r--r-- | src/libcore/path.rs | 20 | ||||
| -rw-r--r-- | src/libcore/repr.rs | 8 | ||||
| -rw-r--r-- | src/libcore/result.rs | 21 | ||||
| -rw-r--r-- | src/libcore/task/mod.rs | 1 |
9 files changed, 11 insertions, 112 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) } |
