diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2012-09-19 18:00:26 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2012-09-20 09:48:05 -0700 |
| commit | 9117dcb968f96d0e9391dfac50348d4c031d89b3 (patch) | |
| tree | a571f0c2ef1f91370cae51527f0e0761212a82e7 /src/libstd | |
| parent | 6b670c306b8de545afcbcea81bcd592c644409d7 (diff) | |
rustc: De-mode all overloaded operators
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/deque.rs | 57 | ||||
| -rw-r--r-- | src/libstd/getopts.rs | 40 | ||||
| -rw-r--r-- | src/libstd/json.rs | 27 | ||||
| -rw-r--r-- | src/libstd/list.rs | 22 | ||||
| -rw-r--r-- | src/libstd/net_url.rs | 43 | ||||
| -rw-r--r-- | src/libstd/test.rs | 9 | ||||
| -rw-r--r-- | src/libstd/time.rs | 36 |
7 files changed, 234 insertions, 0 deletions
diff --git a/src/libstd/deque.rs b/src/libstd/deque.rs index 4c4dcdeabe9..35b147e1940 100644 --- a/src/libstd/deque.rs +++ b/src/libstd/deque.rs @@ -239,6 +239,7 @@ mod tests { type RecCy = {x: int, y: int, t: Taggy}; +#[cfg(stage0)] impl Taggy : Eq { pure fn eq(other: Taggy) -> bool { match self { @@ -258,7 +259,29 @@ mod tests { } pure fn ne(other: Taggy) -> bool { !self.eq(other) } } + #[cfg(stage1)] + #[cfg(stage2)] + impl Taggy : Eq { + pure fn eq(other: &Taggy) -> bool { + match self { + One(a1) => match (*other) { + One(b1) => return a1 == b1, + _ => return false + }, + Two(a1, a2) => match (*other) { + Two(b1, b2) => return a1 == b1 && a2 == b2, + _ => return false + }, + Three(a1, a2, a3) => match (*other) { + Three(b1, b2, b3) => return a1 == b1 && a2 == b2 && a3 == b3, + _ => return false + } + } + } + pure fn ne(other: &Taggy) -> bool { !self.eq(other) } + } +#[cfg(stage0)] impl Taggypar<int> : Eq { //let eq4: EqFn<Taggypar<int>> = |x,y| taggypareq::<int>(x, y); pure fn eq(other: Taggypar<int>) -> bool { @@ -281,13 +304,47 @@ mod tests { } pure fn ne(other: Taggypar<int>) -> bool { !self.eq(other) } } + #[cfg(stage1)] + #[cfg(stage2)] + impl Taggypar<int> : Eq { + //let eq4: EqFn<Taggypar<int>> = |x,y| taggypareq::<int>(x, y); + pure fn eq(other: &Taggypar<int>) -> bool { + match self { + Onepar::<int>(a1) => match (*other) { + Onepar::<int>(b1) => return a1 == b1, + _ => return false + }, + Twopar::<int>(a1, a2) => match (*other) { + Twopar::<int>(b1, b2) => return a1 == b1 && a2 == b2, + _ => return false + }, + Threepar::<int>(a1, a2, a3) => match (*other) { + Threepar::<int>(b1, b2, b3) => { + return a1 == b1 && a2 == b2 && a3 == b3 + } + _ => return false + } + } + } + pure fn ne(other: &Taggypar<int>) -> bool { !self.eq(other) } + } +#[cfg(stage0)] impl RecCy : Eq { pure fn eq(other: RecCy) -> bool { return self.x == other.x && self.y == other.y && self.t == other.t; } pure fn ne(other: RecCy) -> bool { !self.eq(other) } } + #[cfg(stage1)] + #[cfg(stage2)] + impl RecCy : Eq { + pure fn eq(other: &RecCy) -> bool { + return self.x == (*other).x && self.y == (*other).y && + self.t == (*other).t; + } + pure fn ne(other: &RecCy) -> bool { !self.eq(other) } + } #[test] fn test_param_int() { diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index 67d3619b0e2..4a071dea879 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -107,6 +107,7 @@ fn mkname(nm: &str) -> Name { } else { Long(unm) }; } +#[cfg(stage0)] impl Name : Eq { pure fn eq(&&other: Name) -> bool { match self { @@ -126,13 +127,43 @@ impl Name : Eq { } pure fn ne(&&other: Name) -> bool { !self.eq(other) } } +#[cfg(stage1)] +#[cfg(stage2)] +impl Name : Eq { + pure fn eq(other: &Name) -> bool { + match self { + Long(e0a) => { + match (*other) { + Long(e0b) => e0a == e0b, + _ => false + } + } + Short(e0a) => { + match (*other) { + Short(e0b) => e0a == e0b, + _ => false + } + } + } + } + pure fn ne(other: &Name) -> bool { !self.eq(other) } +} +#[cfg(stage0)] impl Occur : Eq { pure fn eq(&&other: Occur) -> bool { (self as uint) == (other as uint) } pure fn ne(&&other: Occur) -> bool { !self.eq(other) } } +#[cfg(stage1)] +#[cfg(stage2)] +impl Occur : Eq { + pure fn eq(other: &Occur) -> bool { + (self as uint) == ((*other) as uint) + } + pure fn ne(other: &Occur) -> bool { !self.eq(other) } +} /// Create an option that is required and takes an argument fn reqopt(name: &str) -> Opt { @@ -447,12 +478,21 @@ enum FailType { UnexpectedArgument_, } +#[cfg(stage0)] impl FailType : Eq { pure fn eq(&&other: FailType) -> bool { (self as uint) == (other as uint) } pure fn ne(&&other: FailType) -> bool { !self.eq(other) } } +#[cfg(stage1)] +#[cfg(stage2)] +impl FailType : Eq { + pure fn eq(other: &FailType) -> bool { + (self as uint) == ((*other) as uint) + } + pure fn ne(other: &FailType) -> bool { !self.eq(other) } +} #[cfg(test)] mod tests { diff --git a/src/libstd/json.rs b/src/libstd/json.rs index b66d69d442f..79fee39a702 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -676,6 +676,7 @@ pure fn lt(value0: Json, value1: Json) -> bool { } } +#[cfg(stage0)] impl Error : Eq { pure fn eq(&&other: Error) -> bool { self.line == other.line && @@ -684,18 +685,44 @@ impl Error : Eq { } pure fn ne(&&other: Error) -> bool { !self.eq(other) } } +#[cfg(stage1)] +#[cfg(stage2)] +impl Error : Eq { + pure fn eq(other: &Error) -> bool { + self.line == (*other).line && + self.col == (*other).col && + self.msg == (*other).msg + } + pure fn ne(other: &Error) -> bool { !self.eq(other) } +} +#[cfg(stage0)] impl Json : Eq { pure fn eq(&&other: Json) -> bool { eq(self, other) } pure fn ne(&&other: Json) -> bool { !self.eq(other) } } +#[cfg(stage1)] +#[cfg(stage2)] +impl Json : Eq { + pure fn eq(other: &Json) -> bool { eq(self, (*other)) } + pure fn ne(other: &Json) -> bool { !self.eq(other) } +} +#[cfg(stage0)] impl Json : Ord { pure fn lt(&&other: Json) -> bool { lt(self, other) } pure fn le(&&other: Json) -> bool { !other.lt(self) } pure fn ge(&&other: Json) -> bool { !self.lt(other) } pure fn gt(&&other: Json) -> bool { other.lt(self) } } +#[cfg(stage1)] +#[cfg(stage2)] +impl Json : Ord { + pure fn lt(other: &Json) -> bool { lt(self, (*other)) } + pure fn le(other: &Json) -> bool { !(*other).lt(&self) } + pure fn ge(other: &Json) -> bool { !self.lt(other) } + pure fn gt(other: &Json) -> bool { (*other).lt(&self) } +} trait ToJson { fn to_json() -> Json; } diff --git a/src/libstd/list.rs b/src/libstd/list.rs index 96d4e32d02b..a9c5e1b0e77 100644 --- a/src/libstd/list.rs +++ b/src/libstd/list.rs @@ -148,6 +148,7 @@ fn each<T>(l: @List<T>, f: fn(T) -> bool) { } } +#[cfg(stage0)] impl<T:Eq> List<T> : Eq { pure fn eq(&&other: List<T>) -> bool { match self { @@ -167,6 +168,27 @@ impl<T:Eq> List<T> : Eq { } pure fn ne(&&other: List<T>) -> bool { !self.eq(other) } } +#[cfg(stage1)] +#[cfg(stage2)] +impl<T:Eq> List<T> : Eq { + pure fn eq(other: &List<T>) -> bool { + match self { + Cons(e0a, e1a) => { + match (*other) { + Cons(e0b, e1b) => e0a == e0b && e1a == e1b, + _ => false + } + } + Nil => { + match (*other) { + Nil => true, + _ => false + } + } + } + } + pure fn ne(other: &List<T>) -> bool { !self.eq(other) } +} #[cfg(test)] mod tests { diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index 493e0cc762c..b56d8471fbf 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -317,12 +317,21 @@ fn userinfo_to_str(+userinfo: UserInfo) -> ~str { } } +#[cfg(stage0)] impl UserInfo : Eq { pure fn eq(&&other: UserInfo) -> bool { self.user == other.user && self.pass == other.pass } pure fn ne(&&other: UserInfo) -> bool { !self.eq(other) } } +#[cfg(stage1)] +#[cfg(stage2)] +impl UserInfo : Eq { + pure fn eq(other: &UserInfo) -> bool { + self.user == (*other).user && self.pass == (*other).pass + } + pure fn ne(other: &UserInfo) -> bool { !self.eq(other) } +} fn query_from_str(rawquery: &str) -> Query { let mut query: Query = ~[]; @@ -377,6 +386,7 @@ enum Input { Unreserved // all other legal characters } +#[cfg(stage0)] impl Input: Eq { pure fn eq(&&other: Input) -> bool { match (self, other) { @@ -390,6 +400,21 @@ impl Input: Eq { } pure fn ne(&&other: Input) -> bool { !self.eq(other) } } +#[cfg(stage1)] +#[cfg(stage2)] +impl Input : Eq { + pure fn eq(other: &Input) -> bool { + match (self, (*other)) { + (Digit, Digit) => true, + (Hex, Hex) => true, + (Unreserved, Unreserved) => true, + (Digit, _) => false, + (Hex, _) => false, + (Unreserved, _) => false + } + } + pure fn ne(other: &Input) -> bool { !self.eq(other) } +} // returns userinfo, host, port, and unparsed part, or an error fn get_authority(rawurl: &str) -> @@ -719,6 +744,7 @@ impl Url: to_str::ToStr { } } +#[cfg(stage0)] impl Url: Eq { pure fn eq(&&other: Url) -> bool { self.scheme == other.scheme @@ -734,6 +760,23 @@ impl Url: Eq { !self.eq(other) } } +#[cfg(stage1)] +#[cfg(stage2)] +impl Url : Eq { + pure fn eq(other: &Url) -> bool { + self.scheme == (*other).scheme + && self.user == (*other).user + && self.host == (*other).host + && self.port == (*other).port + && self.path == (*other).path + && self.query == (*other).query + && self.fragment == (*other).fragment + } + + pure fn ne(other: &Url) -> bool { + !self.eq(other) + } +} impl Url: IterBytes { pure fn iter_bytes(lsb0: bool, f: to_bytes::Cb) { diff --git a/src/libstd/test.rs b/src/libstd/test.rs index 268799dbaea..29d97a8918d 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -95,12 +95,21 @@ fn parse_opts(args: &[~str]) -> OptRes { enum TestResult { TrOk, TrFailed, TrIgnored, } +#[cfg(stage0)] impl TestResult : Eq { pure fn eq(&&other: TestResult) -> bool { (self as uint) == (other as uint) } pure fn ne(&&other: TestResult) -> bool { !self.eq(other) } } +#[cfg(stage1)] +#[cfg(stage2)] +impl TestResult : Eq { + pure fn eq(other: &TestResult) -> bool { + (self as uint) == ((*other) as uint) + } + pure fn ne(other: &TestResult) -> bool { !self.eq(other) } +} type ConsoleTestState = @{out: io::Writer, diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 45ea25c3858..f984f1b733f 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -36,12 +36,21 @@ extern mod rustrt { /// A record specifying a time value in seconds and nanoseconds. type Timespec = {sec: i64, nsec: i32}; +#[cfg(stage0)] impl Timespec : Eq { pure fn eq(&&other: Timespec) -> bool { self.sec == other.sec && self.nsec == other.nsec } pure fn ne(&&other: Timespec) -> bool { !self.eq(other) } } +#[cfg(stage1)] +#[cfg(stage2)] +impl Timespec : Eq { + pure fn eq(other: &Timespec) -> bool { + self.sec == (*other).sec && self.nsec == (*other).nsec + } + pure fn ne(other: &Timespec) -> bool { !self.eq(other) } +} /** * Returns the current time as a `timespec` containing the seconds and @@ -91,6 +100,7 @@ type Tm_ = { tm_nsec: i32, // nanoseconds }; +#[cfg(stage0)] impl Tm_ : Eq { pure fn eq(&&other: Tm_) -> bool { self.tm_sec == other.tm_sec && @@ -108,15 +118,41 @@ impl Tm_ : Eq { } pure fn ne(&&other: Tm_) -> bool { !self.eq(other) } } +#[cfg(stage1)] +#[cfg(stage2)] +impl Tm_ : Eq { + pure fn eq(other: &Tm_) -> bool { + self.tm_sec == (*other).tm_sec && + self.tm_min == (*other).tm_min && + self.tm_hour == (*other).tm_hour && + self.tm_mday == (*other).tm_mday && + self.tm_mon == (*other).tm_mon && + self.tm_year == (*other).tm_year && + self.tm_wday == (*other).tm_wday && + self.tm_yday == (*other).tm_yday && + self.tm_isdst == (*other).tm_isdst && + self.tm_gmtoff == (*other).tm_gmtoff && + self.tm_zone == (*other).tm_zone && + self.tm_nsec == (*other).tm_nsec + } + pure fn ne(other: &Tm_) -> bool { !self.eq(other) } +} enum Tm { Tm_(Tm_) } +#[cfg(stage0)] impl Tm : Eq { pure fn eq(&&other: Tm) -> bool { *self == *other } pure fn ne(&&other: Tm) -> bool { *self != *other } } +#[cfg(stage1)] +#[cfg(stage2)] +impl Tm : Eq { + pure fn eq(other: &Tm) -> bool { *self == *(*other) } + pure fn ne(other: &Tm) -> bool { *self != *(*other) } +} fn empty_tm() -> Tm { Tm_({ |
