libcore: Add explicit self to all overloaded operators but Add and Index. r=brson

This commit is contained in:
Patrick Walton 2012-11-21 12:25:35 -08:00
parent de0268b693
commit 7bc29c62d0
6 changed files with 25 additions and 25 deletions

View file

@ -3,7 +3,7 @@ pub trait MyNum : Add<self,self>, Sub<self,self>, Mul<self,self> {
pub impl int : MyNum {
pure fn add(other: &int) -> int { self + *other }
pure fn sub(other: &int) -> int { self - *other }
pure fn mul(other: &int) -> int { self * *other }
pure fn sub(&self, other: &int) -> int { *self - *other }
pure fn mul(&self, other: &int) -> int { *self * *other }
}

View file

@ -24,7 +24,7 @@ struct cmplx {
}
impl cmplx : ops::Mul<cmplx,cmplx> {
pure fn mul(x: &cmplx) -> cmplx {
pure fn mul(&self, x: &cmplx) -> cmplx {
cmplx {
re: self.re*(*x).re - self.im*(*x).im,
im: self.re*(*x).im + self.im*(*x).re

View file

@ -13,13 +13,13 @@ impl Point : ops::Add<Point,Point> {
}
impl Point : ops::Sub<Point,Point> {
pure fn sub(other: &Point) -> Point {
pure fn sub(&self, other: &Point) -> Point {
Point {x: self.x - (*other).x, y: self.y - (*other).y}
}
}
impl Point : ops::Neg<Point> {
pure fn neg() -> Point {
pure fn neg(&self) -> Point {
Point {x: -self.x, y: -self.y}
}
}
@ -40,7 +40,7 @@ impl Point : cmp::Eq {
fn main() {
let mut p = Point {x: 10, y: 20};
p += Point {x: 101, y: 102};
p -= Point {x: 100, y: 100};
p = p - Point {x: 100, y: 100};
assert p + Point {x: 5, y: 5} == Point {x: 16, y: 27};
assert -p == Point {x: -11, y: -22};
assert p[true] == 11;

View file

@ -3,8 +3,8 @@ trait MyNum : Add<self,self>, Sub<self,self>, Mul<self,self> {
impl int : MyNum {
pure fn add(other: &int) -> int { self + *other }
pure fn sub(other: &int) -> int { self - *other }
pure fn mul(other: &int) -> int { self * *other }
pure fn sub(&self, other: &int) -> int { *self - *other }
pure fn mul(&self, other: &int) -> int { *self * *other }
}
fn f<T:Copy MyNum>(x: T, y: T) -> (T, T, T) {