瀏覽代碼

Update to rust master

Alex Crichton 10 年之前
父節點
當前提交
9848257eae
共有 2 個文件被更改,包括 17 次插入47 次删除
  1. 7 7
      src/bigint.rs
  2. 10 40
      src/traits.rs

+ 7 - 7
src/bigint.rs

@@ -2618,7 +2618,7 @@ mod biguint_tests {
     fn test_factor() {
         fn factor(n: usize) -> BigUint {
             let mut f: BigUint = One::one();
-            for i in range(2, n + 1) {
+            for i in 2..n + 1 {
                 // FIXME(#5992): assignment operator overloads
                 // f *= FromPrimitive::from_usize(i);
                 let bu: BigUint = FromPrimitive::from_usize(i).unwrap();
@@ -2667,7 +2667,7 @@ mod biguint_tests {
     fn test_rand_range() {
         let mut rng = thread_rng();
 
-        for _ in range(0, 10) {
+        for _ in 0..10 {
             assert_eq!(rng.gen_bigint_range(&FromPrimitive::from_usize(236).unwrap(),
                                             &FromPrimitive::from_usize(237).unwrap()),
                        FromPrimitive::from_usize(236).unwrap());
@@ -2675,7 +2675,7 @@ mod biguint_tests {
 
         let l = FromPrimitive::from_usize(403469000 + 2352).unwrap();
         let u = FromPrimitive::from_usize(403469000 + 3513).unwrap();
-        for _ in range(0, 1000) {
+        for _ in 0..1000 {
             let n: BigUint = rng.gen_biguint_below(&u);
             assert!(n < u);
 
@@ -3329,7 +3329,7 @@ mod bigint_tests {
     fn test_rand_range() {
         let mut rng = thread_rng();
 
-        for _ in range(0, 10) {
+        for _ in 0..10 {
             assert_eq!(rng.gen_bigint_range(&FromPrimitive::from_usize(236).unwrap(),
                                             &FromPrimitive::from_usize(237).unwrap()),
                        FromPrimitive::from_usize(236).unwrap());
@@ -3337,7 +3337,7 @@ mod bigint_tests {
 
         fn check(l: BigInt, u: BigInt) {
             let mut rng = thread_rng();
-            for _ in range(0, 1000) {
+            for _ in 0..1000 {
                 let n: BigInt = rng.gen_bigint_range(&l, &u);
                 assert!(n >= l);
                 assert!(n < u);
@@ -3391,7 +3391,7 @@ mod bench {
     fn fib(n: usize) -> BigUint {
         let mut f0: BigUint = Zero::zero();
         let mut f1: BigUint = One::one();
-        for _ in range(0, n) {
+        for _ in 0..n {
             let f2 = f0 + &f1;
             f0 = replace(&mut f1, f2);
         }
@@ -3429,7 +3429,7 @@ mod bench {
         let n = { let one : BigUint = One::one(); one << 1000 };
         b.iter(|| {
             let mut m = n.clone();
-            for _ in range(0, 10) {
+            for _ in 0..10 {
                 m = m >> 1;
             }
         })

+ 10 - 40
src/traits.rs

@@ -323,17 +323,11 @@ impl<T: CheckedAdd + CheckedSub + Zero + PartialOrd + Bounded> Saturating for T
     }
 }
 
-/// Performs addition that returns `None` instead of wrapping around on overflow.
+/// Performs addition that returns `None` instead of wrapping around on
+/// overflow.
 pub trait CheckedAdd: Add<Self, Output = Self> {
-    /// Adds two numbers, checking for overflow. If overflow happens, `None` is returned.
-    ///
-    /// # Example
-    ///
-    /// ```rust
-    /// use num::CheckedAdd;
-    /// assert_eq!(5u16.checked_add(&65530), Some(65535));
-    /// assert_eq!(6u16.checked_add(&65530), None);
-    /// ```
+    /// Adds two numbers, checking for overflow. If overflow happens, `None` is
+    /// returned.
     fn checked_add(&self, v: &Self) -> Option<Self>;
 }
 
@@ -386,15 +380,8 @@ checked_impl!(CheckedAdd, checked_add, i64, intrinsics::i64_add_with_overflow);
 
 /// Performs subtraction that returns `None` instead of wrapping around on underflow.
 pub trait CheckedSub: Sub<Self, Output = Self> {
-    /// Subtracts two numbers, checking for underflow. If underflow happens, `None` is returned.
-    ///
-    /// # Example
-    ///
-    /// ```rust
-    /// use num::CheckedSub;
-    /// assert_eq!((-127i8).checked_sub(&1), Some(-128));
-    /// assert_eq!((-128i8).checked_sub(&1), None);
-    /// ```
+    /// Subtracts two numbers, checking for underflow. If underflow happens,
+    /// `None` is returned.
     fn checked_sub(&self, v: &Self) -> Option<Self>;
 }
 
@@ -421,16 +408,8 @@ checked_impl!(CheckedSub, checked_sub, i64, intrinsics::i64_sub_with_overflow);
 /// Performs multiplication that returns `None` instead of wrapping around on underflow or
 /// overflow.
 pub trait CheckedMul: Mul<Self, Output = Self> {
-    /// Multiplies two numbers, checking for underflow or overflow. If underflow or overflow
-    /// happens, `None` is returned.
-    ///
-    /// # Example
-    ///
-    /// ```rust
-    /// use num::CheckedMul;
-    /// assert_eq!(5u8.checked_mul(&51), Some(255));
-    /// assert_eq!(5u8.checked_mul(&52), None);
-    /// ```
+    /// Multiplies two numbers, checking for underflow or overflow. If underflow
+    /// or overflow happens, `None` is returned.
     fn checked_mul(&self, v: &Self) -> Option<Self>;
 }
 
@@ -457,17 +436,8 @@ checked_impl!(CheckedMul, checked_mul, i64, intrinsics::i64_mul_with_overflow);
 /// Performs division that returns `None` instead of panicking on division by zero and instead of
 /// wrapping around on underflow and overflow.
 pub trait CheckedDiv: Div<Self, Output = Self> {
-    /// Divides two numbers, checking for underflow, overflow and division by zero. If any of that
-    /// happens, `None` is returned.
-    ///
-    /// # Example
-    ///
-    /// ```rust
-    /// use num::CheckedDiv;
-    /// assert_eq!((-127i8).checked_div(&-1), Some(127));
-    /// assert_eq!((-128i8).checked_div(&-1), None);
-    /// assert_eq!((1i8).checked_div(&0), None);
-    /// ```
+    /// Divides two numbers, checking for underflow, overflow and division by
+    /// zero. If any of that happens, `None` is returned.
     fn checked_div(&self, v: &Self) -> Option<Self>;
 }