Skip to content

Commit 318e534

Browse files
committed
rustc: Implement explicit self for Eq and Ord. r=graydon
1 parent 4101587 commit 318e534

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+4175
-92
lines changed

src/compiletest/common.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
enum mode { mode_compile_fail, mode_run_fail, mode_run_pass, mode_pretty, }
22

3+
#[cfg(stage0)]
34
impl mode : cmp::Eq {
45
pure fn eq(other: &mode) -> bool {
56
(*other) as int == self as int
67
}
78
pure fn ne(other: &mode) -> bool { !self.eq(other) }
89
}
10+
#[cfg(stage1)]
11+
#[cfg(stage2)]
12+
impl mode : cmp::Eq {
13+
pure fn eq(&self, other: &mode) -> bool {
14+
(*other) as int == (*self) as int
15+
}
16+
pure fn ne(&self, other: &mode) -> bool { !(*self).eq(other) }
17+
}
918

1019
type config = {
1120
// The library paths required for running the compiler

src/libcargo/cargo.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct Package {
3030
}
3131

3232
impl Package : cmp::Ord {
33+
#[cfg(stage0)]
3334
pure fn lt(other: &Package) -> bool {
3435
if self.name.lt(&(*other).name) { return true; }
3536
if (*other).name.lt(&self.name) { return false; }
@@ -46,9 +47,39 @@ impl Package : cmp::Ord {
4647
if self.versions.lt(&(*other).versions) { return true; }
4748
return false;
4849
}
50+
#[cfg(stage1)]
51+
#[cfg(stage2)]
52+
pure fn lt(&self, other: &Package) -> bool {
53+
if (*self).name.lt(&(*other).name) { return true; }
54+
if (*other).name.lt(&(*self).name) { return false; }
55+
if (*self).uuid.lt(&(*other).uuid) { return true; }
56+
if (*other).uuid.lt(&(*self).uuid) { return false; }
57+
if (*self).url.lt(&(*other).url) { return true; }
58+
if (*other).url.lt(&(*self).url) { return false; }
59+
if (*self).method.lt(&(*other).method) { return true; }
60+
if (*other).method.lt(&(*self).method) { return false; }
61+
if (*self).description.lt(&(*other).description) { return true; }
62+
if (*other).description.lt(&(*self).description) { return false; }
63+
if (*self).tags.lt(&(*other).tags) { return true; }
64+
if (*other).tags.lt(&(*self).tags) { return false; }
65+
if (*self).versions.lt(&(*other).versions) { return true; }
66+
return false;
67+
}
68+
#[cfg(stage0)]
4969
pure fn le(other: &Package) -> bool { !(*other).lt(&self) }
70+
#[cfg(stage1)]
71+
#[cfg(stage2)]
72+
pure fn le(&self, other: &Package) -> bool { !(*other).lt(&(*self)) }
73+
#[cfg(stage0)]
5074
pure fn ge(other: &Package) -> bool { !self.lt(other) }
75+
#[cfg(stage1)]
76+
#[cfg(stage2)]
77+
pure fn ge(&self, other: &Package) -> bool { !(*self).lt(other) }
78+
#[cfg(stage0)]
5179
pure fn gt(other: &Package) -> bool { (*other).lt(&self) }
80+
#[cfg(stage1)]
81+
#[cfg(stage2)]
82+
pure fn gt(&self, other: &Package) -> bool { (*other).lt(&(*self)) }
5283
}
5384

5485
struct Source {
@@ -94,10 +125,20 @@ struct Options {
94125
enum Mode { SystemMode, UserMode, LocalMode }
95126

96127
impl Mode : cmp::Eq {
128+
#[cfg(stage0)]
97129
pure fn eq(other: &Mode) -> bool {
98130
(self as uint) == ((*other) as uint)
99131
}
132+
#[cfg(stage1)]
133+
#[cfg(stage2)]
134+
pure fn eq(&self, other: &Mode) -> bool {
135+
((*self) as uint) == ((*other) as uint)
136+
}
137+
#[cfg(stage0)]
100138
pure fn ne(other: &Mode) -> bool { !self.eq(other) }
139+
#[cfg(stage1)]
140+
#[cfg(stage2)]
141+
pure fn ne(&self, other: &Mode) -> bool { !(*self).eq(other) }
101142
}
102143

103144
fn opts() -> ~[getopts::Opt] {

src/libcore/bool.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,16 @@ pub fn all_values(blk: fn(v: bool)) {
6666
pub pure fn to_bit(v: bool) -> u8 { if v { 1u8 } else { 0u8 } }
6767

6868
impl bool : cmp::Eq {
69+
#[cfg(stage0)]
6970
pure fn eq(other: &bool) -> bool { self == (*other) }
71+
#[cfg(stage1)]
72+
#[cfg(stage2)]
73+
pure fn eq(&self, other: &bool) -> bool { (*self) == (*other) }
74+
#[cfg(stage0)]
7075
pure fn ne(other: &bool) -> bool { self != (*other) }
76+
#[cfg(stage1)]
77+
#[cfg(stage2)]
78+
pure fn ne(&self, other: &bool) -> bool { (*self) != (*other) }
7179
}
7280

7381
#[test]

src/libcore/box.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,39 @@ pub pure fn ptr_eq<T>(a: @T, b: @T) -> bool {
2828
}
2929

3030
impl<T:Eq> @const T : Eq {
31+
#[cfg(stage0)]
3132
pure fn eq(other: &@const T) -> bool { *self == *(*other) }
33+
#[cfg(stage1)]
34+
#[cfg(stage2)]
35+
pure fn eq(&self, other: &@const T) -> bool { *(*self) == *(*other) }
36+
#[cfg(stage0)]
3237
pure fn ne(other: &@const T) -> bool { *self != *(*other) }
38+
#[cfg(stage1)]
39+
#[cfg(stage2)]
40+
pure fn ne(&self, other: &@const T) -> bool { *(*self) != *(*other) }
3341
}
3442

3543
impl<T:Ord> @const T : Ord {
44+
#[cfg(stage0)]
3645
pure fn lt(other: &@const T) -> bool { *self < *(*other) }
46+
#[cfg(stage1)]
47+
#[cfg(stage2)]
48+
pure fn lt(&self, other: &@const T) -> bool { *(*self) < *(*other) }
49+
#[cfg(stage0)]
3750
pure fn le(other: &@const T) -> bool { *self <= *(*other) }
51+
#[cfg(stage1)]
52+
#[cfg(stage2)]
53+
pure fn le(&self, other: &@const T) -> bool { *(*self) <= *(*other) }
54+
#[cfg(stage0)]
3855
pure fn ge(other: &@const T) -> bool { *self >= *(*other) }
56+
#[cfg(stage1)]
57+
#[cfg(stage2)]
58+
pure fn ge(&self, other: &@const T) -> bool { *(*self) >= *(*other) }
59+
#[cfg(stage0)]
3960
pure fn gt(other: &@const T) -> bool { *self > *(*other) }
61+
#[cfg(stage1)]
62+
#[cfg(stage2)]
63+
pure fn gt(&self, other: &@const T) -> bool { *(*self) > *(*other) }
4064
}
4165

4266
#[test]

src/libcore/char.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,16 @@ pub pure fn cmp(a: char, b: char) -> int {
181181
}
182182

183183
impl char : Eq {
184+
#[cfg(stage0)]
184185
pure fn eq(other: &char) -> bool { self == (*other) }
186+
#[cfg(stage1)]
187+
#[cfg(stage2)]
188+
pure fn eq(&self, other: &char) -> bool { (*self) == (*other) }
189+
#[cfg(stage0)]
185190
pure fn ne(other: &char) -> bool { self != (*other) }
191+
#[cfg(stage1)]
192+
#[cfg(stage2)]
193+
pure fn ne(&self, other: &char) -> bool { (*self) != (*other) }
186194
}
187195

188196
#[test]

src/libcore/cmp.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,24 @@ mod nounittest {
3030
* default implementations.
3131
*/
3232
#[lang="ord"]
33+
#[cfg(stage0)]
3334
pub trait Ord {
3435
pure fn lt(other: &self) -> bool;
3536
pure fn le(other: &self) -> bool;
3637
pure fn ge(other: &self) -> bool;
3738
pure fn gt(other: &self) -> bool;
3839
}
3940

41+
#[lang="ord"]
42+
#[cfg(stage1)]
43+
#[cfg(stage2)]
44+
pub trait Ord {
45+
pure fn lt(&self, other: &self) -> bool;
46+
pure fn le(&self, other: &self) -> bool;
47+
pure fn ge(&self, other: &self) -> bool;
48+
pure fn gt(&self, other: &self) -> bool;
49+
}
50+
4051
#[lang="eq"]
4152
/**
4253
* Trait for values that can be compared for equality
@@ -47,10 +58,19 @@ mod nounittest {
4758
* a default implementation.
4859
*/
4960
#[lang="eq"]
61+
#[cfg(stage0)]
5062
pub trait Eq {
5163
pure fn eq(other: &self) -> bool;
5264
pure fn ne(other: &self) -> bool;
5365
}
66+
67+
#[lang="eq"]
68+
#[cfg(stage1)]
69+
#[cfg(stage2)]
70+
pub trait Eq {
71+
pure fn eq(&self, other: &self) -> bool;
72+
pure fn ne(&self, other: &self) -> bool;
73+
}
5474
}
5575

5676
#[cfg(test)]
@@ -60,17 +80,36 @@ mod nounittest {
6080
#[cfg(test)]
6181
mod unittest {
6282
#[legacy_exports];
83+
84+
#[cfg(stage0)]
6385
pub trait Ord {
6486
pure fn lt(other: &self) -> bool;
6587
pure fn le(other: &self) -> bool;
6688
pure fn ge(other: &self) -> bool;
6789
pure fn gt(other: &self) -> bool;
6890
}
6991

92+
#[cfg(stage1)]
93+
#[cfg(stage2)]
94+
pub trait Ord {
95+
pure fn lt(&self, other: &self) -> bool;
96+
pure fn le(&self, other: &self) -> bool;
97+
pure fn ge(&self, other: &self) -> bool;
98+
pure fn gt(&self, other: &self) -> bool;
99+
}
100+
101+
#[cfg(stage0)]
70102
pub trait Eq {
71103
pure fn eq(other: &self) -> bool;
72104
pure fn ne(other: &self) -> bool;
73105
}
106+
107+
#[cfg(stage1)]
108+
#[cfg(stage2)]
109+
pub trait Eq {
110+
pure fn eq(&self, other: &self) -> bool;
111+
pure fn ne(&self, other: &self) -> bool;
112+
}
74113
}
75114

76115
#[cfg(notest)]

src/libcore/either.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ pub pure fn unwrap_right<T,U>(eith: Either<T,U>) -> U {
132132
}
133133

134134
impl<T:Eq,U:Eq> Either<T,U> : Eq {
135+
#[cfg(stage0)]
135136
pure fn eq(other: &Either<T,U>) -> bool {
136137
match self {
137138
Left(ref a) => {
@@ -148,7 +149,29 @@ impl<T:Eq,U:Eq> Either<T,U> : Eq {
148149
}
149150
}
150151
}
152+
#[cfg(stage1)]
153+
#[cfg(stage2)]
154+
pure fn eq(&self, other: &Either<T,U>) -> bool {
155+
match (*self) {
156+
Left(ref a) => {
157+
match (*other) {
158+
Left(ref b) => (*a).eq(b),
159+
Right(_) => false
160+
}
161+
}
162+
Right(ref a) => {
163+
match (*other) {
164+
Left(_) => false,
165+
Right(ref b) => (*a).eq(b)
166+
}
167+
}
168+
}
169+
}
170+
#[cfg(stage0)]
151171
pure fn ne(other: &Either<T,U>) -> bool { !self.eq(other) }
172+
#[cfg(stage1)]
173+
#[cfg(stage2)]
174+
pure fn ne(&self, other: &Either<T,U>) -> bool { !(*self).eq(other) }
152175
}
153176

154177
#[test]

src/libcore/extfmt.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ pub mod rt {
394394
pub enum PadMode { PadSigned, PadUnsigned, PadNozero, PadFloat }
395395

396396
pub impl PadMode : Eq {
397+
#[cfg(stage0)]
397398
pure fn eq(other: &PadMode) -> bool {
398399
match (self, (*other)) {
399400
(PadSigned, PadSigned) => true,
@@ -406,7 +407,25 @@ pub mod rt {
406407
(PadFloat, _) => false
407408
}
408409
}
410+
#[cfg(stage1)]
411+
#[cfg(stage2)]
412+
pure fn eq(&self, other: &PadMode) -> bool {
413+
match ((*self), (*other)) {
414+
(PadSigned, PadSigned) => true,
415+
(PadUnsigned, PadUnsigned) => true,
416+
(PadNozero, PadNozero) => true,
417+
(PadFloat, PadFloat) => true,
418+
(PadSigned, _) => false,
419+
(PadUnsigned, _) => false,
420+
(PadNozero, _) => false,
421+
(PadFloat, _) => false
422+
}
423+
}
424+
#[cfg(stage0)]
409425
pure fn ne(other: &PadMode) -> bool { !self.eq(other) }
426+
#[cfg(stage1)]
427+
#[cfg(stage2)]
428+
pure fn ne(&self, other: &PadMode) -> bool { !(*self).eq(other) }
410429
}
411430

412431
pub fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str {

src/libcore/float.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,39 @@ pub pure fn cos(x: float) -> float { f64::cos(x as f64) as float }
400400
pub pure fn tan(x: float) -> float { f64::tan(x as f64) as float }
401401

402402
impl float : Eq {
403+
#[cfg(stage0)]
403404
pub pure fn eq(other: &float) -> bool { self == (*other) }
405+
#[cfg(stage1)]
406+
#[cfg(stage2)]
407+
pure fn eq(&self, other: &float) -> bool { (*self) == (*other) }
408+
#[cfg(stage0)]
404409
pub pure fn ne(other: &float) -> bool { self != (*other) }
410+
#[cfg(stage1)]
411+
#[cfg(stage2)]
412+
pure fn ne(&self, other: &float) -> bool { (*self) != (*other) }
405413
}
406414

407415
impl float : Ord {
416+
#[cfg(stage0)]
408417
pub pure fn lt(other: &float) -> bool { self < (*other) }
418+
#[cfg(stage1)]
419+
#[cfg(stage2)]
420+
pure fn lt(&self, other: &float) -> bool { (*self) < (*other) }
421+
#[cfg(stage0)]
409422
pub pure fn le(other: &float) -> bool { self <= (*other) }
423+
#[cfg(stage1)]
424+
#[cfg(stage2)]
425+
pure fn le(&self, other: &float) -> bool { (*self) <= (*other) }
426+
#[cfg(stage0)]
410427
pub pure fn ge(other: &float) -> bool { self >= (*other) }
428+
#[cfg(stage1)]
429+
#[cfg(stage2)]
430+
pure fn ge(&self, other: &float) -> bool { (*self) >= (*other) }
431+
#[cfg(stage0)]
411432
pub pure fn gt(other: &float) -> bool { self > (*other) }
433+
#[cfg(stage1)]
434+
#[cfg(stage2)]
435+
pure fn gt(&self, other: &float) -> bool { (*self) > (*other) }
412436
}
413437

414438
impl float: num::Num {

src/libcore/int-template.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,39 @@ pub pure fn abs(i: T) -> T {
5555
}
5656

5757
impl T : Ord {
58+
#[cfg(stage0)]
5859
pure fn lt(other: &T) -> bool { return self < (*other); }
60+
#[cfg(stage1)]
61+
#[cfg(stage2)]
62+
pure fn lt(&self, other: &T) -> bool { return (*self) < (*other); }
63+
#[cfg(stage0)]
5964
pure fn le(other: &T) -> bool { return self <= (*other); }
65+
#[cfg(stage1)]
66+
#[cfg(stage2)]
67+
pure fn le(&self, other: &T) -> bool { return (*self) <= (*other); }
68+
#[cfg(stage0)]
6069
pure fn ge(other: &T) -> bool { return self >= (*other); }
70+
#[cfg(stage1)]
71+
#[cfg(stage2)]
72+
pure fn ge(&self, other: &T) -> bool { return (*self) >= (*other); }
73+
#[cfg(stage0)]
6174
pure fn gt(other: &T) -> bool { return self > (*other); }
75+
#[cfg(stage1)]
76+
#[cfg(stage2)]
77+
pure fn gt(&self, other: &T) -> bool { return (*self) > (*other); }
6278
}
6379

6480
impl T : Eq {
81+
#[cfg(stage0)]
6582
pure fn eq(other: &T) -> bool { return self == (*other); }
83+
#[cfg(stage1)]
84+
#[cfg(stage2)]
85+
pure fn eq(&self, other: &T) -> bool { return (*self) == (*other); }
86+
#[cfg(stage0)]
6687
pure fn ne(other: &T) -> bool { return self != (*other); }
88+
#[cfg(stage1)]
89+
#[cfg(stage2)]
90+
pure fn ne(&self, other: &T) -> bool { return (*self) != (*other); }
6791
}
6892

6993
impl T: num::Num {

0 commit comments

Comments
 (0)