diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-08-08 11:38:10 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2013-08-27 18:47:57 -0700 |
| commit | 8693943676487c01fa09f5f3daf0df6a1f71e24d (patch) | |
| tree | 5aa978e4144d51f320d069d88fe0fad4ed40705e /src/libextra/num | |
| parent | 3b6314c39bfc13b5a41c53f13c3fafa7ad91e062 (diff) | |
| download | rust-8693943676487c01fa09f5f3daf0df6a1f71e24d.tar.gz rust-8693943676487c01fa09f5f3daf0df6a1f71e24d.zip | |
librustc: Ensure that type parameters are in the right positions in paths.
This removes the stacking of type parameters that occurs when invoking trait methods, and fixes all places in the standard library that were relying on it. It is somewhat awkward in places; I think we'll probably want something like the `Foo::<for T>::new()` syntax.
Diffstat (limited to 'src/libextra/num')
| -rw-r--r-- | src/libextra/num/bigint.rs | 61 | ||||
| -rw-r--r-- | src/libextra/num/rational.rs | 29 |
2 files changed, 62 insertions, 28 deletions
diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs index 9222dea13c4..ed35f2b6179 100644 --- a/src/libextra/num/bigint.rs +++ b/src/libextra/num/bigint.rs @@ -359,7 +359,7 @@ impl Integer for BigUint { fn div_mod_floor_inner(a: BigUint, b: BigUint) -> (BigUint, BigUint) { let mut m = a; - let mut d = Zero::zero::<BigUint>(); + let mut d: BigUint = Zero::zero(); let mut n = 1; while m >= b { let (d0, d_unit, b_unit) = div_estimate(&m, &b, n); @@ -411,8 +411,9 @@ impl Integer for BigUint { if shift == 0 { return (BigUint::new(d), One::one(), (*b).clone()); } + let one: BigUint = One::one(); return (BigUint::from_slice(d).shl_unit(shift), - One::one::<BigUint>().shl_unit(shift), + one.shl_unit(shift), b.shl_unit(shift)); } } @@ -1445,11 +1446,18 @@ mod biguint_tests { #[test] fn test_is_even() { - assert!(FromStr::from_str::<BigUint>("1").unwrap().is_odd()); - assert!(FromStr::from_str::<BigUint>("2").unwrap().is_even()); - assert!(FromStr::from_str::<BigUint>("1000").unwrap().is_even()); - assert!(FromStr::from_str::<BigUint>("1000000000000000000000").unwrap().is_even()); - assert!(FromStr::from_str::<BigUint>("1000000000000000000001").unwrap().is_odd()); + let one: Option<BigUint> = FromStr::from_str("1"); + let two: Option<BigUint> = FromStr::from_str("2"); + let thousand: Option<BigUint> = FromStr::from_str("1000"); + let big: Option<BigUint> = + FromStr::from_str("1000000000000000000000"); + let bigger: Option<BigUint> = + FromStr::from_str("1000000000000000000001"); + assert!(one.unwrap().is_odd()); + assert!(two.unwrap().is_even()); + assert!(thousand.unwrap().is_even()); + assert!(big.unwrap().is_even()); + assert!(bigger.unwrap().is_odd()); assert!((BigUint::from_uint(1) << 64).is_even()); assert!(((BigUint::from_uint(1) << 64) + BigUint::from_uint(1)).is_odd()); } @@ -1534,15 +1542,19 @@ mod biguint_tests { } } - assert_eq!(FromStrRadix::from_str_radix::<BigUint>("Z", 10), None); - assert_eq!(FromStrRadix::from_str_radix::<BigUint>("_", 2), None); - assert_eq!(FromStrRadix::from_str_radix::<BigUint>("-1", 10), None); + let zed: Option<BigUint> = FromStrRadix::from_str_radix("Z", 10); + assert_eq!(zed, None); + let blank: Option<BigUint> = FromStrRadix::from_str_radix("_", 2); + assert_eq!(blank, None); + let minus_one: Option<BigUint> = FromStrRadix::from_str_radix("-1", + 10); + assert_eq!(minus_one, None); } #[test] fn test_factor() { fn factor(n: uint) -> BigUint { - let mut f= One::one::<BigUint>(); + let mut f: BigUint = One::one(); for i in range(2, n + 1) { // FIXME(#6102): Assignment operator for BigInt causes ICE // f *= BigUint::from_uint(i); @@ -1939,17 +1951,24 @@ mod bigint_tests { #[test] fn test_abs_sub() { - assert_eq!((-One::one::<BigInt>()).abs_sub(&One::one()), Zero::zero()); - assert_eq!(One::one::<BigInt>().abs_sub(&One::one()), Zero::zero()); - assert_eq!(One::one::<BigInt>().abs_sub(&Zero::zero()), One::one()); - assert_eq!(One::one::<BigInt>().abs_sub(&-One::one::<BigInt>()), - IntConvertible::from_int(2)); + let zero: BigInt = Zero::zero(); + let one: BigInt = One::one(); + assert_eq!((-one).abs_sub(&one), zero); + let one: BigInt = One::one(); + let zero: BigInt = Zero::zero(); + assert_eq!(one.abs_sub(&one), zero); + let one: BigInt = One::one(); + let zero: BigInt = Zero::zero(); + assert_eq!(one.abs_sub(&zero), one); + let one: BigInt = One::one(); + assert_eq!(one.abs_sub(&-one), IntConvertible::from_int(2)); } #[test] fn test_to_str_radix() { fn check(n: int, ans: &str) { - assert!(ans == IntConvertible::from_int::<BigInt>(n).to_str_radix(10)); + let n: BigInt = IntConvertible::from_int(n); + assert!(ans == n.to_str_radix(10)); } check(10, "10"); check(1, "1"); @@ -1962,7 +1981,10 @@ mod bigint_tests { #[test] fn test_from_str_radix() { fn check(s: &str, ans: Option<int>) { - let ans = ans.map_move(|n| IntConvertible::from_int::<BigInt>(n)); + let ans = ans.map_move(|n| { + let x: BigInt = IntConvertible::from_int(n); + x + }); assert_eq!(FromStrRadix::from_str_radix(s, 10), ans); } check("10", Some(10)); @@ -1980,7 +2002,8 @@ mod bigint_tests { BigInt::new(Minus, ~[1, 1, 1])); assert!(-BigInt::new(Minus, ~[1, 1, 1]) == BigInt::new(Plus, ~[1, 1, 1])); - assert_eq!(-Zero::zero::<BigInt>(), Zero::zero::<BigInt>()); + let zero: BigInt = Zero::zero(); + assert_eq!(-zero, zero); } } diff --git a/src/libextra/num/rational.rs b/src/libextra/num/rational.rs index 60dd36a3b88..41e9a488bf8 100644 --- a/src/libextra/num/rational.rs +++ b/src/libextra/num/rational.rs @@ -269,9 +269,13 @@ impl<T: FromStr + Clone + Integer + Ord> /// Parses `numer/denom`. fn from_str(s: &str) -> Option<Ratio<T>> { let split: ~[&str] = s.splitn_iter('/', 1).collect(); - if split.len() < 2 { return None; } - do FromStr::from_str::<T>(split[0]).chain |a| { - do FromStr::from_str::<T>(split[1]).chain |b| { + if split.len() < 2 { + return None + } + let a_option: Option<T> = FromStr::from_str(split[0]); + do a_option.chain |a| { + let b_option: Option<T> = FromStr::from_str(split[1]); + do b_option.chain |b| { Some(Ratio::new(a.clone(), b.clone())) } } @@ -282,10 +286,15 @@ impl<T: FromStrRadix + Clone + Integer + Ord> /// Parses `numer/denom` where the numbers are in base `radix`. fn from_str_radix(s: &str, radix: uint) -> Option<Ratio<T>> { let split: ~[&str] = s.splitn_iter('/', 1).collect(); - if split.len() < 2 { None } - else { - do FromStrRadix::from_str_radix::<T>(split[0], radix).chain |a| { - do FromStrRadix::from_str_radix::<T>(split[1], radix).chain |b| { + if split.len() < 2 { + None + } else { + let a_option: Option<T> = FromStrRadix::from_str_radix(split[0], + radix); + do a_option.chain |a| { + let b_option: Option<T> = + FromStrRadix::from_str_radix(split[1], radix); + do b_option.chain |b| { Some(Ratio::new(a.clone(), b.clone())) } } @@ -496,7 +505,8 @@ mod test { #[test] fn test_from_str_fail() { fn test(s: &str) { - assert_eq!(FromStr::from_str::<Rational>(s), None); + let rational: Option<Rational> = FromStr::from_str(s); + assert_eq!(rational, None); } let xs = ["0 /1", "abc", "", "1/", "--1/2","3/2/1"]; @@ -536,7 +546,8 @@ mod test { #[test] fn test_from_str_radix_fail() { fn test(s: &str) { - assert_eq!(FromStrRadix::from_str_radix::<Rational>(s, 3), None); + let radix: Option<Rational> = FromStrRadix::from_str_radix(s, 3); + assert_eq!(radix, None); } let xs = ["0 /1", "abc", "", "1/", "--1/2","3/2/1", "3/2"]; |
