diff --git a/src/libcore/f32.rs b/src/libcore/f32.rs index 3b4af904eee1..9fbf902170ae 100644 --- a/src/libcore/f32.rs +++ b/src/libcore/f32.rs @@ -163,14 +163,14 @@ impl f32 : cmp::Ord { } impl f32: num::Num { - pure fn add(other: &f32) -> f32 { return self + *other; } - pure fn sub(other: &f32) -> f32 { return self - *other; } - pure fn mul(other: &f32) -> f32 { return self * *other; } - pure fn div(other: &f32) -> f32 { return self / *other; } - pure fn modulo(other: &f32) -> f32 { return self % *other; } - pure fn neg() -> f32 { return -self; } + pure fn add(&self, other: &f32) -> f32 { return *self + *other; } + pure fn sub(&self, other: &f32) -> f32 { return *self - *other; } + pure fn mul(&self, other: &f32) -> f32 { return *self * *other; } + pure fn div(&self, other: &f32) -> f32 { return *self / *other; } + pure fn modulo(&self, other: &f32) -> f32 { return *self % *other; } + pure fn neg(&self) -> f32 { return -*self; } - pure fn to_int() -> int { return self as int; } + pure fn to_int(&self) -> int { return *self as int; } static pure fn from_int(n: int) -> f32 { return n as f32; } } diff --git a/src/libcore/f64.rs b/src/libcore/f64.rs index 360da91f654a..86565f9e2528 100644 --- a/src/libcore/f64.rs +++ b/src/libcore/f64.rs @@ -182,14 +182,14 @@ impl f64 : cmp::Ord { } impl f64: num::Num { - pure fn add(other: &f64) -> f64 { return self + *other; } - pure fn sub(other: &f64) -> f64 { return self - *other; } - pure fn mul(other: &f64) -> f64 { return self * *other; } - pure fn div(other: &f64) -> f64 { return self / *other; } - pure fn modulo(other: &f64) -> f64 { return self % *other; } - pure fn neg() -> f64 { return -self; } + pure fn add(&self, other: &f64) -> f64 { return *self + *other; } + pure fn sub(&self, other: &f64) -> f64 { return *self - *other; } + pure fn mul(&self, other: &f64) -> f64 { return *self * *other; } + pure fn div(&self, other: &f64) -> f64 { return *self / *other; } + pure fn modulo(&self, other: &f64) -> f64 { return *self % *other; } + pure fn neg(&self) -> f64 { return -*self; } - pure fn to_int() -> int { return self as int; } + pure fn to_int(&self) -> int { return *self as int; } static pure fn from_int(n: int) -> f64 { return n as f64; } } diff --git a/src/libcore/float.rs b/src/libcore/float.rs index d95b7a276b28..2a86d7ae04fd 100644 --- a/src/libcore/float.rs +++ b/src/libcore/float.rs @@ -425,22 +425,22 @@ impl float : Ord { impl float: num::Num { #[inline(always)] - pub pure fn add(other: &float) -> float { return self + *other; } + pub pure fn add(&self, other: &float) -> float { return *self + *other; } #[inline(always)] - pub pure fn sub(other: &float) -> float { return self - *other; } + pub pure fn sub(&self, other: &float) -> float { return *self - *other; } #[inline(always)] - pub pure fn mul(other: &float) -> float { return self * *other; } + pub pure fn mul(&self, other: &float) -> float { return *self * *other; } #[inline(always)] - pub pure fn div(other: &float) -> float { return self / *other; } + pub pure fn div(&self, other: &float) -> float { return *self / *other; } #[inline(always)] - pure fn modulo(other: &float) -> float { return self % *other; } + pure fn modulo(&self, other: &float) -> float { return *self % *other; } #[inline(always)] - pure fn neg() -> float { return -self; } + pure fn neg(&self) -> float { return -*self; } #[inline(always)] - pure fn to_int() -> int { return self as int; } + pure fn to_int(&self) -> int { return *self as int; } #[inline(always)] - static pure fn from_int(n: int) -> float { return n as float; } + static pure fn from_int(&self, n: int) -> float { return n as float; } } #[test] diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs index 5b80745b972c..dbeb51b813ff 100644 --- a/src/libcore/int-template.rs +++ b/src/libcore/int-template.rs @@ -79,14 +79,14 @@ impl T : Eq { } impl T: num::Num { - pure fn add(other: &T) -> T { return self + *other; } - pure fn sub(other: &T) -> T { return self - *other; } - pure fn mul(other: &T) -> T { return self * *other; } - pure fn div(other: &T) -> T { return self / *other; } - pure fn modulo(other: &T) -> T { return self % *other; } - pure fn neg() -> T { return -self; } + pure fn add(&self, other: &T) -> T { return *self + *other; } + pure fn sub(&self, other: &T) -> T { return *self - *other; } + pure fn mul(&self, other: &T) -> T { return *self * *other; } + pure fn div(&self, other: &T) -> T { return *self / *other; } + pure fn modulo(&self, other: &T) -> T { return *self % *other; } + pure fn neg(&self) -> T { return -*self; } - pure fn to_int() -> int { return self as int; } + pure fn to_int(&self) -> int { return *self as int; } static pure fn from_int(n: int) -> T { return n as T; } } diff --git a/src/libcore/num.rs b/src/libcore/num.rs index bc36c3c2fff8..fed9db8767b9 100644 --- a/src/libcore/num.rs +++ b/src/libcore/num.rs @@ -12,13 +12,13 @@ pub trait Num { // FIXME: Trait composition. (#2616) - pure fn add(other: &self) -> self; - pure fn sub(other: &self) -> self; - pure fn mul(other: &self) -> self; - pure fn div(other: &self) -> self; - pure fn modulo(other: &self) -> self; - pure fn neg() -> self; + pure fn add(&self, other: &self) -> self; + pure fn sub(&self, other: &self) -> self; + pure fn mul(&self, other: &self) -> self; + pure fn div(&self, other: &self) -> self; + pure fn modulo(&self, other: &self) -> self; + pure fn neg(&self) -> self; - pure fn to_int() -> int; + pure fn to_int(&self) -> int; static pure fn from_int(n: int) -> self; } diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs index 17f766195837..8a03b0f94bcd 100644 --- a/src/libcore/uint-template.rs +++ b/src/libcore/uint-template.rs @@ -73,14 +73,14 @@ impl T : Eq { } impl T: num::Num { - pure fn add(other: &T) -> T { return self + *other; } - pure fn sub(other: &T) -> T { return self - *other; } - pure fn mul(other: &T) -> T { return self * *other; } - pure fn div(other: &T) -> T { return self / *other; } - pure fn modulo(other: &T) -> T { return self % *other; } - pure fn neg() -> T { return -self; } + pure fn add(&self, other: &T) -> T { return *self + *other; } + pure fn sub(&self, other: &T) -> T { return *self - *other; } + pure fn mul(&self, other: &T) -> T { return *self * *other; } + pure fn div(&self, other: &T) -> T { return *self / *other; } + pure fn modulo(&self, other: &T) -> T { return *self % *other; } + pure fn neg(&self) -> T { return -*self; } - pure fn to_int() -> int { return self as int; } + pure fn to_int(&self) -> int { return *self as int; } static pure fn from_int(n: int) -> T { return n as T; } } diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 220a0a7e6bb8..2473011be0d2 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -59,27 +59,25 @@ impl BytePos: cmp::Ord { pure fn gt(&self, other: &BytePos) -> bool { **self > **other } } -impl BytePos: Num { - pure fn add(other: &BytePos) -> BytePos { - BytePos(*self + **other) +#[cfg(stage0)] +impl BytePos: Add { + pure fn add(rhs: &BytePos) -> BytePos { + BytePos(*self + **rhs) } - pure fn sub(other: &BytePos) -> BytePos { - BytePos(*self - **other) +} + +#[cfg(stage1)] +#[cfg(stage2)] +impl BytePos: Add { + pure fn add(&self, rhs: &BytePos) -> BytePos { + BytePos(**self + **rhs) } - pure fn mul(other: &BytePos) -> BytePos { - BytePos(*self * (**other)) +} + +impl BytePos: Sub { + pure fn sub(&self, rhs: &BytePos) -> BytePos { + BytePos(**self - **rhs) } - pure fn div(other: &BytePos) -> BytePos { - BytePos(*self / **other) - } - pure fn modulo(other: &BytePos) -> BytePos { - BytePos(*self % **other) - } - pure fn neg() -> BytePos { - BytePos(-*self) - } - pure fn to_int() -> int { *self as int } - static pure fn from_int(+n: int) -> BytePos { BytePos(n as uint) } } impl BytePos: to_bytes::IterBytes { @@ -105,35 +103,33 @@ impl CharPos: cmp::Ord { pure fn gt(&self, other: &CharPos) -> bool { **self > **other } } -impl CharPos: Num { - pure fn add(other: &CharPos) -> CharPos { - CharPos(*self + **other) - } - pure fn sub(other: &CharPos) -> CharPos { - CharPos(*self - **other) - } - pure fn mul(other: &CharPos) -> CharPos { - CharPos(*self * (**other)) - } - pure fn div(other: &CharPos) -> CharPos { - CharPos(*self / **other) - } - pure fn modulo(other: &CharPos) -> CharPos { - CharPos(*self % **other) - } - pure fn neg() -> CharPos { - CharPos(-*self) - } - pure fn to_int() -> int { *self as int } - static pure fn from_int(+n: int) -> CharPos { CharPos(n as uint) } -} - impl CharPos: to_bytes::IterBytes { pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) { (**self).iter_bytes(lsb0, f) } } +#[cfg(stage0)] +impl CharPos: Add { + pure fn add(rhs: &CharPos) -> CharPos { + CharPos(*self + **rhs) + } +} + +#[cfg(stage1)] +#[cfg(stage2)] +impl CharPos: Add { + pure fn add(&self, rhs: &CharPos) -> CharPos { + CharPos(**self + **rhs) + } +} + +impl CharPos: Sub { + pure fn sub(&self, rhs: &CharPos) -> CharPos { + CharPos(**self - **rhs) + } +} + /** Spans represent a region of code, used for error reporting. Positions in spans are *absolute* positions from the beginning of the codemap, not positions