Skip to content

Commit 7bc29c6

Browse files
committed
libcore: Add explicit self to all overloaded operators but Add and Index. r=brson
1 parent de0268b commit 7bc29c6

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

src/libcore/ops.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,52 +35,52 @@ pub trait Add<RHS,Result> {
3535

3636
#[lang="sub"]
3737
pub trait Sub<RHS,Result> {
38-
pure fn sub(rhs: &RHS) -> Result;
38+
pure fn sub(&self, rhs: &RHS) -> Result;
3939
}
4040

4141
#[lang="mul"]
4242
pub trait Mul<RHS,Result> {
43-
pure fn mul(rhs: &RHS) -> Result;
43+
pure fn mul(&self, rhs: &RHS) -> Result;
4444
}
4545

4646
#[lang="div"]
4747
pub trait Div<RHS,Result> {
48-
pure fn div(rhs: &RHS) -> Result;
48+
pure fn div(&self, rhs: &RHS) -> Result;
4949
}
5050

5151
#[lang="modulo"]
5252
pub trait Modulo<RHS,Result> {
53-
pure fn modulo(rhs: &RHS) -> Result;
53+
pure fn modulo(&self, rhs: &RHS) -> Result;
5454
}
5555

5656
#[lang="neg"]
5757
pub trait Neg<Result> {
58-
pure fn neg() -> Result;
58+
pure fn neg(&self) -> Result;
5959
}
6060

6161
#[lang="bitand"]
6262
pub trait BitAnd<RHS,Result> {
63-
pure fn bitand(rhs: &RHS) -> Result;
63+
pure fn bitand(&self, rhs: &RHS) -> Result;
6464
}
6565

6666
#[lang="bitor"]
6767
pub trait BitOr<RHS,Result> {
68-
pure fn bitor(rhs: &RHS) -> Result;
68+
pure fn bitor(&self, rhs: &RHS) -> Result;
6969
}
7070

7171
#[lang="bitxor"]
7272
pub trait BitXor<RHS,Result> {
73-
pure fn bitxor(rhs: &RHS) -> Result;
73+
pure fn bitxor(&self, rhs: &RHS) -> Result;
7474
}
7575

7676
#[lang="shl"]
7777
pub trait Shl<RHS,Result> {
78-
pure fn shl(rhs: &RHS) -> Result;
78+
pure fn shl(&self, rhs: &RHS) -> Result;
7979
}
8080

8181
#[lang="shr"]
8282
pub trait Shr<RHS,Result> {
83-
pure fn shr(rhs: &RHS) -> Result;
83+
pure fn shr(&self, rhs: &RHS) -> Result;
8484
}
8585

8686
#[lang="index"]

src/librustc/middle/ty.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,25 +2041,25 @@ fn remove_copyable(k: Kind) -> Kind {
20412041
}
20422042
20432043
impl Kind : ops::BitAnd<Kind,Kind> {
2044-
pure fn bitand(other: &Kind) -> Kind {
2044+
pure fn bitand(&self, other: &Kind) -> Kind {
20452045
unsafe {
2046-
lower_kind(self, (*other))
2046+
lower_kind(*self, *other)
20472047
}
20482048
}
20492049
}
20502050
20512051
impl Kind : ops::BitOr<Kind,Kind> {
2052-
pure fn bitor(other: &Kind) -> Kind {
2052+
pure fn bitor(&self, other: &Kind) -> Kind {
20532053
unsafe {
2054-
raise_kind(self, (*other))
2054+
raise_kind(*self, *other)
20552055
}
20562056
}
20572057
}
20582058
20592059
impl Kind : ops::Sub<Kind,Kind> {
2060-
pure fn sub(other: &Kind) -> Kind {
2060+
pure fn sub(&self, other: &Kind) -> Kind {
20612061
unsafe {
2062-
kind_(*self & !*(*other))
2062+
kind_(**self & !**other)
20632063
}
20642064
}
20652065
}
@@ -2309,7 +2309,7 @@ fn type_kind(cx: ctxt, ty: t) -> Kind {
23092309
// arbitrary threshold to prevent by-value copying of big records
23102310
if kind_is_safe_for_default_mode(result) {
23112311
if type_size(cx, ty) > 4 {
2312-
result -= kind_(KIND_MASK_DEFAULT_MODE);
2312+
result = result - kind_(KIND_MASK_DEFAULT_MODE);
23132313
}
23142314
}
23152315

src/test/auxiliary/trait_inheritance_overloading_xc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub trait MyNum : Add<self,self>, Sub<self,self>, Mul<self,self> {
33

44
pub impl int : MyNum {
55
pure fn add(other: &int) -> int { self + *other }
6-
pure fn sub(other: &int) -> int { self - *other }
7-
pure fn mul(other: &int) -> int { self * *other }
6+
pure fn sub(&self, other: &int) -> int { *self - *other }
7+
pure fn mul(&self, other: &int) -> int { *self * *other }
88
}
99

src/test/bench/shootout-mandelbrot.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct cmplx {
2424
}
2525

2626
impl cmplx : ops::Mul<cmplx,cmplx> {
27-
pure fn mul(x: &cmplx) -> cmplx {
27+
pure fn mul(&self, x: &cmplx) -> cmplx {
2828
cmplx {
2929
re: self.re*(*x).re - self.im*(*x).im,
3030
im: self.re*(*x).im + self.im*(*x).re

src/test/run-pass/operator-overloading.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ impl Point : ops::Add<Point,Point> {
1313
}
1414

1515
impl Point : ops::Sub<Point,Point> {
16-
pure fn sub(other: &Point) -> Point {
16+
pure fn sub(&self, other: &Point) -> Point {
1717
Point {x: self.x - (*other).x, y: self.y - (*other).y}
1818
}
1919
}
2020

2121
impl Point : ops::Neg<Point> {
22-
pure fn neg() -> Point {
22+
pure fn neg(&self) -> Point {
2323
Point {x: -self.x, y: -self.y}
2424
}
2525
}
@@ -40,7 +40,7 @@ impl Point : cmp::Eq {
4040
fn main() {
4141
let mut p = Point {x: 10, y: 20};
4242
p += Point {x: 101, y: 102};
43-
p -= Point {x: 100, y: 100};
43+
p = p - Point {x: 100, y: 100};
4444
assert p + Point {x: 5, y: 5} == Point {x: 16, y: 27};
4545
assert -p == Point {x: -11, y: -22};
4646
assert p[true] == 11;

src/test/run-pass/trait-inheritance-overloading.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ trait MyNum : Add<self,self>, Sub<self,self>, Mul<self,self> {
33

44
impl int : MyNum {
55
pure fn add(other: &int) -> int { self + *other }
6-
pure fn sub(other: &int) -> int { self - *other }
7-
pure fn mul(other: &int) -> int { self * *other }
6+
pure fn sub(&self, other: &int) -> int { *self - *other }
7+
pure fn mul(&self, other: &int) -> int { *self * *other }
88
}
99

1010
fn f<T:Copy MyNum>(x: T, y: T) -> (T, T, T) {

0 commit comments

Comments
 (0)