about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libcore/f32.rs16
-rw-r--r--src/libcore/f64.rs16
-rw-r--r--src/libcore/float.rs16
-rw-r--r--src/libcore/int-template.rs16
-rw-r--r--src/libcore/num.rs14
-rw-r--r--src/libcore/uint-template.rs16
-rw-r--r--src/libsyntax/codemap.rs74
7 files changed, 82 insertions, 86 deletions
diff --git a/src/libcore/f32.rs b/src/libcore/f32.rs
index 3b4af904eee..9fbf902170a 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 to_int()         -> int { return self as int; }
+    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(&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 360da91f654..86565f9e252 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 to_int()         -> int { return self as int; }
+    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(&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 d95b7a276b2..2a86d7ae04f 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 5b80745b972..dbeb51b813f 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 to_int()         -> int { return self as int; }
+    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(&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 bc36c3c2fff..fed9db8767b 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 17f76619583..8a03b0f94bc 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 to_int()         -> int { return self as int; }
+    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(&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 220a0a7e6bb..2473011be0d 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<BytePos, BytePos> {
+    pure fn add(rhs: &BytePos) -> BytePos {
+        BytePos(*self + **rhs)
     }
-    pure fn sub(other: &BytePos) -> BytePos {
-        BytePos(*self - **other)
-    }
-    pure fn mul(other: &BytePos) -> BytePos {
-        BytePos(*self * (**other))
-    }
-    pure fn div(other: &BytePos) -> BytePos {
-        BytePos(*self / **other)
-    }
-    pure fn modulo(other: &BytePos) -> BytePos {
-        BytePos(*self % **other)
+}
+
+#[cfg(stage1)]
+#[cfg(stage2)]
+impl BytePos: Add<BytePos, BytePos> {
+    pure fn add(&self, rhs: &BytePos) -> BytePos {
+        BytePos(**self + **rhs)
     }
-    pure fn neg() -> BytePos {
-        BytePos(-*self)
+}
+
+impl BytePos: Sub<BytePos, BytePos> {
+    pure fn sub(&self, rhs: &BytePos) -> BytePos {
+        BytePos(**self - **rhs)
     }
-    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,32 +103,30 @@ 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)
+impl CharPos: to_bytes::IterBytes {
+    pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) {
+        (**self).iter_bytes(lsb0, f)
     }
-    pure fn modulo(other: &CharPos) -> CharPos {
-        CharPos(*self % **other)
+}
+
+#[cfg(stage0)]
+impl CharPos: Add<CharPos, CharPos> {
+    pure fn add(rhs: &CharPos) -> CharPos {
+        CharPos(*self + **rhs)
     }
-    pure fn neg() -> CharPos {
-        CharPos(-*self)
+}
+
+#[cfg(stage1)]
+#[cfg(stage2)]
+impl CharPos: Add<CharPos, CharPos> {
+    pure fn add(&self, rhs: &CharPos) -> CharPos {
+        CharPos(**self + **rhs)
     }
-    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)
+impl CharPos: Sub<CharPos, CharPos> {
+    pure fn sub(&self, rhs: &CharPos) -> CharPos {
+        CharPos(**self - **rhs)
     }
 }