Skip to content

Commit d809e89

Browse files
committed
Replace some Eq impls with deriving_eq
1 parent 742f354 commit d809e89

File tree

13 files changed

+24
-263
lines changed

13 files changed

+24
-263
lines changed

src/libcore/core.rc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ mod core {
240240
pub const warn : u32 = 2_u32;
241241
pub const info : u32 = 3_u32;
242242
pub const debug : u32 = 4_u32;
243+
244+
pub use cmp;
243245
}
244246

245247

src/libcore/either.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use cmp::Eq;
1818
use result::Result;
1919

2020
/// The either type
21+
#[deriving_eq]
2122
pub enum Either<T, U> {
2223
Left(T),
2324
Right(U)
@@ -141,26 +142,6 @@ pub pure fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
141142
}
142143
}
143144

144-
impl<T:Eq,U:Eq> Either<T,U> : Eq {
145-
pure fn eq(&self, other: &Either<T,U>) -> bool {
146-
match (*self) {
147-
Left(ref a) => {
148-
match (*other) {
149-
Left(ref b) => (*a).eq(b),
150-
Right(_) => false
151-
}
152-
}
153-
Right(ref a) => {
154-
match (*other) {
155-
Left(_) => false,
156-
Right(ref b) => (*a).eq(b)
157-
}
158-
}
159-
}
160-
}
161-
pure fn ne(&self, other: &Either<T,U>) -> bool { !(*self).eq(other) }
162-
}
163-
164145
#[test]
165146
fn test_either_left() {
166147
let val = Left(10);

src/libcore/extfmt.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -445,24 +445,9 @@ pub mod rt {
445445
};
446446
}
447447

448+
#[deriving_eq]
448449
pub enum PadMode { PadSigned, PadUnsigned, PadNozero, PadFloat }
449450

450-
pub impl PadMode : Eq {
451-
pure fn eq(&self, other: &PadMode) -> bool {
452-
match ((*self), (*other)) {
453-
(PadSigned, PadSigned) => true,
454-
(PadUnsigned, PadUnsigned) => true,
455-
(PadNozero, PadNozero) => true,
456-
(PadFloat, PadFloat) => true,
457-
(PadSigned, _) => false,
458-
(PadUnsigned, _) => false,
459-
(PadNozero, _) => false,
460-
(PadFloat, _) => false
461-
}
462-
}
463-
pure fn ne(&self, other: &PadMode) -> bool { !(*self).eq(other) }
464-
}
465-
466451
pub fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str {
467452
let mut s = move s; // sadtimes
468453
let uwidth : uint = match cv.width {

src/libcore/io.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -523,18 +523,9 @@ pub pure fn with_str_reader<T>(s: &str, f: fn(Reader) -> T) -> T {
523523
pub enum FileFlag { Append, Create, Truncate, NoFlag, }
524524
525525
// What type of writer are we?
526+
#[deriving_eq]
526527
pub enum WriterType { Screen, File }
527528
528-
pub impl WriterType : Eq {
529-
pure fn eq(&self, other: &WriterType) -> bool {
530-
match ((*self), (*other)) {
531-
(Screen, Screen) | (File, File) => true,
532-
(Screen, _) | (File, _) => false
533-
}
534-
}
535-
pure fn ne(&self, other: &WriterType) -> bool { !(*self).eq(other) }
536-
}
537-
538529
// FIXME (#2004): Seekable really should be orthogonal.
539530
// FIXME (#2004): eventually u64
540531
/// The raw underlying writer trait. All writers must implement this.

src/libcore/option.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ let unwrapped_msg = match move msg {
4747
use cmp::Eq;
4848

4949
/// The option type
50+
#[deriving_eq]
5051
pub enum Option<T> {
5152
None,
5253
Some(T),
@@ -310,27 +311,6 @@ impl<T: Copy> Option<T> {
310311
pure fn while_some(blk: fn(v: T) -> Option<T>) { while_some(self, blk) }
311312
}
312313

313-
impl<T: Eq> Option<T> : Eq {
314-
pure fn eq(&self, other: &Option<T>) -> bool {
315-
match (*self) {
316-
None => {
317-
match (*other) {
318-
None => true,
319-
Some(_) => false
320-
}
321-
}
322-
Some(ref self_contents) => {
323-
match (*other) {
324-
None => false,
325-
Some(ref other_contents) =>
326-
(*self_contents).eq(other_contents)
327-
}
328-
}
329-
}
330-
}
331-
pure fn ne(&self, other: &Option<T>) -> bool { !(*self).eq(other) }
332-
}
333-
334314
#[test]
335315
fn test_unwrap_ptr() {
336316
let x = ~0;

src/libcore/path.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Cross-platform file path handling
2020

2121
use cmp::Eq;
2222

23+
#[deriving_eq]
2324
pub struct WindowsPath {
2425
host: Option<~str>,
2526
device: Option<~str>,
@@ -31,6 +32,7 @@ pub pure fn WindowsPath(s: &str) -> WindowsPath {
3132
from_str(s)
3233
}
3334

35+
#[deriving_eq]
3436
pub struct PosixPath {
3537
is_absolute: bool,
3638
components: ~[~str],
@@ -356,24 +358,6 @@ impl PosixPath : ToStr {
356358
}
357359
}
358360

359-
impl PosixPath : Eq {
360-
pure fn eq(&self, other: &PosixPath) -> bool {
361-
return (*self).is_absolute == (*other).is_absolute &&
362-
(*self).components == (*other).components;
363-
}
364-
pure fn ne(&self, other: &PosixPath) -> bool { !(*self).eq(other) }
365-
}
366-
367-
impl WindowsPath : Eq {
368-
pure fn eq(&self, other: &WindowsPath) -> bool {
369-
return (*self).host == (*other).host &&
370-
(*self).device == (*other).device &&
371-
(*self).is_absolute == (*other).is_absolute &&
372-
(*self).components == (*other).components;
373-
}
374-
pure fn ne(&self, other: &WindowsPath) -> bool { !(*self).eq(other) }
375-
}
376-
377361
// FIXME (#3227): when default methods in traits are working, de-duplicate
378362
// PosixPath and WindowsPath, most of their methods are common.
379363
impl PosixPath : GenericPath {

src/libcore/repr.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -518,20 +518,14 @@ fn test_repr2() {
518518

519519
// Old non-factored implementation, transitional...
520520

521+
#[deriving_eq]
521522
enum EnumVisitState {
522523
PreVariant, // We're before the variant we're interested in.
523524
InVariant, // We're inside the variant we're interested in.
524525
PostVariant, // We're after the variant we're interested in.
525526
Degenerate // This is a degenerate enum (exactly 1 variant)
526527
}
527528

528-
impl EnumVisitState : cmp::Eq {
529-
pure fn eq(&self, other: &EnumVisitState) -> bool {
530-
((*self) as uint) == ((*other) as uint)
531-
}
532-
pure fn ne(&self, other: &EnumVisitState) -> bool { !(*self).eq(other) }
533-
}
534-
535529
struct EnumState {
536530
end_ptr: *c_void,
537531
state: EnumVisitState

src/libcore/result.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use cmp::Eq;
1919
use either::Either;
2020

2121
/// The result type
22+
#[deriving_eq]
2223
pub enum Result<T, U> {
2324
/// Contains the successful result value
2425
Ok(T),
@@ -374,26 +375,6 @@ pub fn unwrap_err<T, U>(res: Result<T, U>) -> U {
374375
}
375376
}
376377

377-
impl<T:Eq,U:Eq> Result<T,U> : Eq {
378-
pure fn eq(&self, other: &Result<T,U>) -> bool {
379-
match (*self) {
380-
Ok(ref e0a) => {
381-
match (*other) {
382-
Ok(ref e0b) => *e0a == *e0b,
383-
_ => false
384-
}
385-
}
386-
Err(ref e0a) => {
387-
match (*other) {
388-
Err(ref e0b) => *e0a == *e0b,
389-
_ => false
390-
}
391-
}
392-
}
393-
}
394-
pure fn ne(&self, other: &Result<T,U>) -> bool { !(*self).eq(other) }
395-
}
396-
397378
#[cfg(test)]
398379
#[allow(non_implicitly_copyable_typarams)]
399380
mod tests {

src/libcore/task/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub enum Task {
5555
TaskHandle(task_id)
5656
}
5757

58+
// XXX: deriving
5859
impl Task : cmp::Eq {
5960
pure fn eq(&self, other: &Task) -> bool { *(*self) == *(*other) }
6061
pure fn ne(&self, other: &Task) -> bool { !(*self).eq(other) }

0 commit comments

Comments
 (0)