Skip to content

Commit 45677ee

Browse files
committed
replace impls with deriving where applicable
1 parent 2b83def commit 45677ee

File tree

6 files changed

+7
-63
lines changed

6 files changed

+7
-63
lines changed

src/libcore/pipes.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ bounded and unbounded protocols allows for less code duplication.
8282
8383
*/
8484

85-
use cmp::Eq;
8685
use cast::{forget, reinterpret_cast, transmute};
8786
use cell::Cell;
8887
use either::{Either, Left, Right};
@@ -103,20 +102,14 @@ macro_rules! move_it (
103102
)
104103

105104
#[doc(hidden)]
105+
#[deriving(Eq)]
106106
enum State {
107107
Empty,
108108
Full,
109109
Blocked,
110110
Terminated
111111
}
112112

113-
impl Eq for State {
114-
fn eq(&self, other: &State) -> bool {
115-
((*self) as uint) == ((*other) as uint)
116-
}
117-
fn ne(&self, other: &State) -> bool { !(*self).eq(other) }
118-
}
119-
120113
pub struct BufferHeader {
121114
// Tracks whether this buffer needs to be freed. We can probably
122115
// get away with restricting it to 0 or 1, if we're careful.

src/libcore/task/mod.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,12 @@ pub enum Task {
7272
* If you wish for this result's delivery to block until all linked and/or
7373
* children tasks complete, recommend using a result future.
7474
*/
75+
#[deriving(Eq)]
7576
pub enum TaskResult {
7677
Success,
7778
Failure,
7879
}
7980

80-
impl Eq for TaskResult {
81-
fn eq(&self, other: &TaskResult) -> bool {
82-
match ((*self), (*other)) {
83-
(Success, Success) | (Failure, Failure) => true,
84-
(Success, _) | (Failure, _) => false
85-
}
86-
}
87-
fn ne(&self, other: &TaskResult) -> bool { !(*self).eq(other) }
88-
}
89-
9081
/// Scheduler modes
9182
#[deriving(Eq)]
9283
pub enum SchedMode {

src/libcore/vec.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,12 +2533,7 @@ impl<A:Copy> iter::CopyableNonstrictIter<A> for @[A] {
25332533
impl<A:Clone> Clone for ~[A] {
25342534
#[inline]
25352535
fn clone(&self) -> ~[A] {
2536-
let mut dolly = ~[];
2537-
vec::reserve(&mut dolly, self.len());
2538-
for self.each |item| {
2539-
dolly.push(item.clone());
2540-
}
2541-
return dolly;
2536+
self.map(|item| item.clone())
25422537
}
25432538
}
25442539

src/libstd/bigint.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,13 +557,9 @@ priv fn get_radix_base(radix: uint) -> (uint, uint) {
557557
}
558558

559559
/// A Sign is a BigInt's composing element.
560+
#[deriving(Eq)]
560561
pub enum Sign { Minus, Zero, Plus }
561562

562-
impl Eq for Sign {
563-
fn eq(&self, other: &Sign) -> bool { self.cmp(other) == 0 }
564-
fn ne(&self, other: &Sign) -> bool { self.cmp(other) != 0 }
565-
}
566-
567563
impl Ord for Sign {
568564
fn lt(&self, other: &Sign) -> bool { self.cmp(other) < 0 }
569565
fn le(&self, other: &Sign) -> bool { self.cmp(other) <= 0 }

src/libstd/json.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub enum Json {
3535
pub type List = ~[Json];
3636
pub type Object = LinearMap<~str, Json>;
3737

38+
#[deriving(Eq)]
3839
pub struct Error {
3940
line: uint,
4041
col: uint,
@@ -1060,15 +1061,6 @@ impl Ord for Json {
10601061
fn gt(&self, other: &Json) -> bool { (*other).lt(&(*self)) }
10611062
}
10621063
1063-
impl Eq for Error {
1064-
fn eq(&self, other: &Error) -> bool {
1065-
(*self).line == other.line &&
1066-
(*self).col == other.col &&
1067-
(*self).msg == other.msg
1068-
}
1069-
fn ne(&self, other: &Error) -> bool { !(*self).eq(other) }
1070-
}
1071-
10721064
trait ToJson { fn to_json(&self) -> Json; }
10731065
10741066
impl ToJson for Json {

src/libstd/time.rs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub mod rustrt {
4040
/// A record specifying a time value in seconds and nanoseconds.
4141
#[auto_encode]
4242
#[auto_decode]
43+
#[deriving(Eq)]
4344
pub struct Timespec { sec: i64, nsec: i32 }
4445

4546
/*
@@ -57,13 +58,6 @@ pub impl Timespec {
5758
}
5859
}
5960

60-
impl Eq for Timespec {
61-
fn eq(&self, other: &Timespec) -> bool {
62-
self.sec == other.sec && self.nsec == other.nsec
63-
}
64-
fn ne(&self, other: &Timespec) -> bool { !self.eq(other) }
65-
}
66-
6761
impl Ord for Timespec {
6862
fn lt(&self, other: &Timespec) -> bool {
6963
self.sec < other.sec ||
@@ -117,6 +111,7 @@ pub fn tzset() {
117111

118112
#[auto_encode]
119113
#[auto_decode]
114+
#[deriving(Eq)]
120115
pub struct Tm {
121116
tm_sec: i32, // seconds after the minute ~[0-60]
122117
tm_min: i32, // minutes after the hour ~[0-59]
@@ -132,24 +127,6 @@ pub struct Tm {
132127
tm_nsec: i32, // nanoseconds
133128
}
134129

135-
impl Eq for Tm {
136-
fn eq(&self, other: &Tm) -> bool {
137-
self.tm_sec == (*other).tm_sec &&
138-
self.tm_min == (*other).tm_min &&
139-
self.tm_hour == (*other).tm_hour &&
140-
self.tm_mday == (*other).tm_mday &&
141-
self.tm_mon == (*other).tm_mon &&
142-
self.tm_year == (*other).tm_year &&
143-
self.tm_wday == (*other).tm_wday &&
144-
self.tm_yday == (*other).tm_yday &&
145-
self.tm_isdst == (*other).tm_isdst &&
146-
self.tm_gmtoff == (*other).tm_gmtoff &&
147-
self.tm_zone == (*other).tm_zone &&
148-
self.tm_nsec == (*other).tm_nsec
149-
}
150-
fn ne(&self, other: &Tm) -> bool { !self.eq(other) }
151-
}
152-
153130
pub fn empty_tm() -> Tm {
154131
Tm {
155132
tm_sec: 0_i32,

0 commit comments

Comments
 (0)