From 9848257eae04138044e1ea90fbeb2170f55498ef Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 19 Mar 2015 09:57:18 -0700 Subject: [PATCH] Update to rust master --- src/bigint.rs | 14 +++++++------- src/traits.rs | 50 ++++++++++---------------------------------------- 2 files changed, 17 insertions(+), 47 deletions(-) diff --git a/src/bigint.rs b/src/bigint.rs index cf69fdf..6c88d09 100644 --- a/src/bigint.rs +++ b/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; } }) diff --git a/src/traits.rs b/src/traits.rs index 0e5d413..0f44aee 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -323,17 +323,11 @@ impl 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 { - /// 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; } @@ -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 { - /// 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; } @@ -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 { - /// 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; } @@ -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 { - /// 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; }