about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2012-08-14 20:03:31 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2012-08-14 20:03:31 -0700
commitccd36439f70814073c567bb22fdbcaafcf970b16 (patch)
tree6fb5ae755f4dafa8b9c7ee256d15008d376baf69
parentf78c90653535128b5a7c08d4850d6ef202beba40 (diff)
Make Num::from_int a static method
-rw-r--r--src/libcore/f32.rs2
-rw-r--r--src/libcore/f64.rs2
-rw-r--r--src/libcore/float.rs14
-rw-r--r--src/libcore/int-template.rs16
-rw-r--r--src/libcore/num.rs5
-rw-r--r--src/libcore/uint-template.rs2
6 files changed, 19 insertions, 22 deletions
diff --git a/src/libcore/f32.rs b/src/libcore/f32.rs
index 81eacbb6462..e1cf9946284 100644
--- a/src/libcore/f32.rs
+++ b/src/libcore/f32.rs
@@ -180,7 +180,7 @@ impl f32: num::Num {
     pure fn neg()                -> f32 { return -self;        }
 
     pure fn to_int()         -> int { return self as int; }
-    pure fn from_int(n: int) -> f32 { return n as f32;    }
+    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 5b2d7daaa15..3abfd44e838 100644
--- a/src/libcore/f64.rs
+++ b/src/libcore/f64.rs
@@ -207,7 +207,7 @@ impl f64: num::Num {
     pure fn neg()                -> f64 { return -self;        }
 
     pure fn to_int()         -> int { return self as int; }
-    pure fn from_int(n: int) -> f64 { return n as f64;    }
+    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 79e89714728..943f075b319 100644
--- a/src/libcore/float.rs
+++ b/src/libcore/float.rs
@@ -422,7 +422,7 @@ impl float: num::Num {
     pure fn neg()                  -> float { return -self;        }
 
     pure fn to_int()         -> int   { return self as int; }
-    pure fn from_int(n: int) -> float { return n as float;  }
+    static pure fn from_int(n: int) -> float { return n as float;  }
 }
 
 #[test]
@@ -523,14 +523,14 @@ fn test_traits() {
     fn test<U:num::Num>(ten: &U) {
         assert (ten.to_int() == 10);
 
-        let two = ten.from_int(2);
+        let two = from_int(2);
         assert (two.to_int() == 2);
 
-        assert (ten.add(two) == ten.from_int(12));
-        assert (ten.sub(two) == ten.from_int(8));
-        assert (ten.mul(two) == ten.from_int(20));
-        assert (ten.div(two) == ten.from_int(5));
-        assert (ten.modulo(two) == ten.from_int(0));
+        assert (ten.add(two) == from_int(12));
+        assert (ten.sub(two) == from_int(8));
+        assert (ten.mul(two) == from_int(20));
+        assert (ten.div(two) == from_int(5));
+        assert (ten.modulo(two) == from_int(0));
     }
 
     test(&10.0);
diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs
index dd0892f7100..b310b1f34f5 100644
--- a/src/libcore/int-template.rs
+++ b/src/libcore/int-template.rs
@@ -84,7 +84,7 @@ impl T: num::Num {
     pure fn neg()              -> T { return -self;        }
 
     pure fn to_int()         -> int { return self as int; }
-    pure fn from_int(n: int) -> T   { return n as T;      }
+    static pure fn from_int(n: int) -> T   { return n as T;      }
 }
 
 impl T: iter::times {
@@ -238,15 +238,15 @@ fn test_interfaces() {
     fn test<U:num::Num>(ten: U) {
         assert (ten.to_int() == 10);
 
-        let two = ten.from_int(2);
+        let two = from_int(2);
         assert (two.to_int() == 2);
 
-        assert (ten.add(two) == ten.from_int(12));
-        assert (ten.sub(two) == ten.from_int(8));
-        assert (ten.mul(two) == ten.from_int(20));
-        assert (ten.div(two) == ten.from_int(5));
-        assert (ten.modulo(two) == ten.from_int(0));
-        assert (ten.neg() == ten.from_int(-10));
+        assert (ten.add(two) == from_int(12));
+        assert (ten.sub(two) == from_int(8));
+        assert (ten.mul(two) == from_int(20));
+        assert (ten.div(two) == from_int(5));
+        assert (ten.modulo(two) == from_int(0));
+        assert (ten.neg() == from_int(-10));
     }
 
     test(10 as T);
diff --git a/src/libcore/num.rs b/src/libcore/num.rs
index a06c4e419e5..c414d6190c8 100644
--- a/src/libcore/num.rs
+++ b/src/libcore/num.rs
@@ -1,7 +1,6 @@
 /// An interface for numbers.
 
 trait Num {
-    // FIXME: Cross-crate overloading doesn't work yet. (#2615)
     // FIXME: Trait composition. (#2616)
     pure fn add(&&other: self) -> self;
     pure fn sub(&&other: self) -> self;
@@ -11,7 +10,5 @@ trait Num {
     pure fn neg() -> self;
 
     pure fn to_int() -> int;
-    pure fn from_int(n: int) -> self;    // FIXME (#2376) Static functions.
-    // n.b. #2376 is for classes, not traits, but it could be generalized...
+    static pure fn from_int(n: int) -> self;
 }
-
diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs
index 162b0d39838..0fc35156f3a 100644
--- a/src/libcore/uint-template.rs
+++ b/src/libcore/uint-template.rs
@@ -77,7 +77,7 @@ impl T: num::Num {
     pure fn neg()              -> T { return -self;        }
 
     pure fn to_int()         -> int { return self as int; }
-    pure fn from_int(n: int) -> T   { return n as T;      }
+    static pure fn from_int(n: int) -> T   { return n as T;      }
 }
 
 impl T: iter::times {