Skip to content

Commit

Permalink
libcore: Add explicit self to all overloaded operators but Add and In…
Browse files Browse the repository at this point in the history
…dex. r=brson
  • Loading branch information
pcwalton committed Nov 27, 2012
1 parent de0268b commit 7bc29c6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
20 changes: 10 additions & 10 deletions src/libcore/ops.rs
Expand Up @@ -35,52 +35,52 @@ pub trait Add<RHS,Result> {

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

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

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

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

#[lang="neg"]
pub trait Neg<Result> {
pure fn neg() -> Result;
pure fn neg(&self) -> Result;
}

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

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

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

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

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

#[lang="index"]
Expand Down
14 changes: 7 additions & 7 deletions src/librustc/middle/ty.rs
Expand Up @@ -2041,25 +2041,25 @@ fn remove_copyable(k: Kind) -> Kind {
}

impl Kind : ops::BitAnd<Kind,Kind> {
pure fn bitand(other: &Kind) -> Kind {
pure fn bitand(&self, other: &Kind) -> Kind {
unsafe {
lower_kind(self, (*other))
lower_kind(*self, *other)
}
}
}

impl Kind : ops::BitOr<Kind,Kind> {
pure fn bitor(other: &Kind) -> Kind {
pure fn bitor(&self, other: &Kind) -> Kind {
unsafe {
raise_kind(self, (*other))
raise_kind(*self, *other)
}
}
}

impl Kind : ops::Sub<Kind,Kind> {
pure fn sub(other: &Kind) -> Kind {
pure fn sub(&self, other: &Kind) -> Kind {
unsafe {
kind_(*self & !*(*other))
kind_(**self & !**other)
}
}
}
Expand Down Expand Up @@ -2309,7 +2309,7 @@ fn type_kind(cx: ctxt, ty: t) -> Kind {
// arbitrary threshold to prevent by-value copying of big records
if kind_is_safe_for_default_mode(result) {
if type_size(cx, ty) > 4 {
result -= kind_(KIND_MASK_DEFAULT_MODE);
result = result - kind_(KIND_MASK_DEFAULT_MODE);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/auxiliary/trait_inheritance_overloading_xc.rs
Expand Up @@ -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 }
}

2 changes: 1 addition & 1 deletion src/test/bench/shootout-mandelbrot.rs
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/test/run-pass/operator-overloading.rs
Expand Up @@ -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}
}
}
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/test/run-pass/trait-inheritance-overloading.rs
Expand Up @@ -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) {
Expand Down

0 comments on commit 7bc29c6

Please sign in to comment.