@@ -359,7 +359,7 @@ impl Integer for BigUint {
359359
360360 fn div_mod_floor_inner ( a : BigUint , b : BigUint ) -> ( BigUint , BigUint ) {
361361 let mut m = a;
362- let mut d = Zero :: zero :: < BigUint > ( ) ;
362+ let mut d: BigUint = Zero :: zero ( ) ;
363363 let mut n = 1 ;
364364 while m >= b {
365365 let ( d0, d_unit, b_unit) = div_estimate ( & m, & b, n) ;
@@ -411,8 +411,9 @@ impl Integer for BigUint {
411411 if shift == 0 {
412412 return ( BigUint :: new ( d) , One :: one ( ) , ( * b) . clone ( ) ) ;
413413 }
414+ let one: BigUint = One :: one ( ) ;
414415 return ( BigUint :: from_slice ( d) . shl_unit ( shift) ,
415- One :: one :: < BigUint > ( ) . shl_unit ( shift) ,
416+ one. shl_unit ( shift) ,
416417 b. shl_unit ( shift) ) ;
417418 }
418419 }
@@ -1168,8 +1169,8 @@ mod biguint_tests {
11681169 #[test]
11691170 fn test_shl() {
11701171 fn check(s: &str, shift: uint, ans: &str) {
1171- let bu = ( FromStrRadix::from_str_radix::<BigUint> (s, 16).unwrap() << shift)
1172- .to_str_radix(16);
1172+ let opt_biguint: Option<BigUint> = FromStrRadix::from_str_radix(s, 16);
1173+ let bu = (opt_biguint.unwrap() << shift) .to_str_radix(16);
11731174 assert_eq!(bu.as_slice(), ans);
11741175 }
11751176
@@ -1206,8 +1207,9 @@ mod biguint_tests {
12061207 #[ test]
12071208 fn test_shr( ) {
12081209 fn check( s: & str, shift: uint, ans: & str) {
1209- let bu = ( FromStrRadix :: from_str_radix:: < BigUint > ( s, 16 ) . unwrap( ) >> shift)
1210- . to_str_radix( 16 ) ;
1210+ let opt_biguint: Option < BigUint > =
1211+ FromStrRadix :: from_str_radix( s, 16 ) ;
1212+ let bu = ( opt_biguint. unwrap( ) >> shift) . to_str_radix( 16 ) ;
12111213 assert_eq ! ( bu. as_slice( ) , ans) ;
12121214 }
12131215
@@ -1445,11 +1447,18 @@ mod biguint_tests {
14451447
14461448 #[ test]
14471449 fn test_is_even ( ) {
1448- assert ! ( FromStr :: from_str:: <BigUint >( "1" ) . unwrap( ) . is_odd( ) ) ;
1449- assert ! ( FromStr :: from_str:: <BigUint >( "2" ) . unwrap( ) . is_even( ) ) ;
1450- assert ! ( FromStr :: from_str:: <BigUint >( "1000" ) . unwrap( ) . is_even( ) ) ;
1451- assert ! ( FromStr :: from_str:: <BigUint >( "1000000000000000000000" ) . unwrap( ) . is_even( ) ) ;
1452- assert ! ( FromStr :: from_str:: <BigUint >( "1000000000000000000001" ) . unwrap( ) . is_odd( ) ) ;
1450+ let one: Option < BigUint > = FromStr :: from_str ( "1" ) ;
1451+ let two: Option < BigUint > = FromStr :: from_str ( "2" ) ;
1452+ let thousand: Option < BigUint > = FromStr :: from_str ( "1000" ) ;
1453+ let big: Option < BigUint > =
1454+ FromStr :: from_str ( "1000000000000000000000" ) ;
1455+ let bigger: Option < BigUint > =
1456+ FromStr :: from_str ( "1000000000000000000001" ) ;
1457+ assert ! ( one. unwrap( ) . is_odd( ) ) ;
1458+ assert ! ( two. unwrap( ) . is_even( ) ) ;
1459+ assert ! ( thousand. unwrap( ) . is_even( ) ) ;
1460+ assert ! ( big. unwrap( ) . is_even( ) ) ;
1461+ assert ! ( bigger. unwrap( ) . is_odd( ) ) ;
14531462 assert ! ( ( BigUint :: from_uint( 1 ) << 64 ) . is_even( ) ) ;
14541463 assert ! ( ( ( BigUint :: from_uint( 1 ) << 64 ) + BigUint :: from_uint( 1 ) ) . is_odd( ) ) ;
14551464 }
@@ -1534,15 +1543,19 @@ mod biguint_tests {
15341543 }
15351544 }
15361545
1537- assert_eq ! ( FromStrRadix :: from_str_radix:: <BigUint >( "Z" , 10 ) , None ) ;
1538- assert_eq ! ( FromStrRadix :: from_str_radix:: <BigUint >( "_" , 2 ) , None ) ;
1539- assert_eq ! ( FromStrRadix :: from_str_radix:: <BigUint >( "-1" , 10 ) , None ) ;
1546+ let zed: Option < BigUint > = FromStrRadix :: from_str_radix ( "Z" , 10 ) ;
1547+ assert_eq ! ( zed, None ) ;
1548+ let blank: Option < BigUint > = FromStrRadix :: from_str_radix ( "_" , 2 ) ;
1549+ assert_eq ! ( blank, None ) ;
1550+ let minus_one: Option < BigUint > = FromStrRadix :: from_str_radix ( "-1" ,
1551+ 10 ) ;
1552+ assert_eq ! ( minus_one, None ) ;
15401553 }
15411554
15421555 #[ test]
15431556 fn test_factor ( ) {
15441557 fn factor ( n : uint ) -> BigUint {
1545- let mut f= One :: one :: < BigUint > ( ) ;
1558+ let mut f: BigUint = One :: one ( ) ;
15461559 for i in range ( 2 , n + 1 ) {
15471560 // FIXME(#6102): Assignment operator for BigInt causes ICE
15481561 // f *= BigUint::from_uint(i);
@@ -1939,17 +1952,24 @@ mod bigint_tests {
19391952
19401953 #[ test]
19411954 fn test_abs_sub ( ) {
1942- assert_eq ! ( ( -One :: one:: <BigInt >( ) ) . abs_sub( & One :: one( ) ) , Zero :: zero( ) ) ;
1943- assert_eq ! ( One :: one:: <BigInt >( ) . abs_sub( & One :: one( ) ) , Zero :: zero( ) ) ;
1944- assert_eq ! ( One :: one:: <BigInt >( ) . abs_sub( & Zero :: zero( ) ) , One :: one( ) ) ;
1945- assert_eq ! ( One :: one:: <BigInt >( ) . abs_sub( & -One :: one:: <BigInt >( ) ) ,
1946- IntConvertible :: from_int( 2 ) ) ;
1955+ let zero: BigInt = Zero :: zero ( ) ;
1956+ let one: BigInt = One :: one ( ) ;
1957+ assert_eq ! ( ( -one) . abs_sub( & one) , zero) ;
1958+ let one: BigInt = One :: one ( ) ;
1959+ let zero: BigInt = Zero :: zero ( ) ;
1960+ assert_eq ! ( one. abs_sub( & one) , zero) ;
1961+ let one: BigInt = One :: one ( ) ;
1962+ let zero: BigInt = Zero :: zero ( ) ;
1963+ assert_eq ! ( one. abs_sub( & zero) , one) ;
1964+ let one: BigInt = One :: one ( ) ;
1965+ assert_eq ! ( one. abs_sub( & -one) , IntConvertible :: from_int( 2 ) ) ;
19471966 }
19481967
19491968 #[ test]
19501969 fn test_to_str_radix ( ) {
19511970 fn check ( n : int , ans : & str ) {
1952- assert ! ( ans == IntConvertible :: from_int:: <BigInt >( n) . to_str_radix( 10 ) ) ;
1971+ let n: BigInt = IntConvertible :: from_int ( n) ;
1972+ assert ! ( ans == n. to_str_radix( 10 ) ) ;
19531973 }
19541974 check ( 10 , "10" ) ;
19551975 check ( 1 , "1" ) ;
@@ -1962,7 +1982,10 @@ mod bigint_tests {
19621982 #[ test]
19631983 fn test_from_str_radix ( ) {
19641984 fn check ( s : & str , ans : Option < int > ) {
1965- let ans = ans. map_move ( |n| IntConvertible :: from_int :: < BigInt > ( n) ) ;
1985+ let ans = ans. map_move ( |n| {
1986+ let x: BigInt = IntConvertible :: from_int ( n) ;
1987+ x
1988+ } ) ;
19661989 assert_eq ! ( FromStrRadix :: from_str_radix( s, 10 ) , ans) ;
19671990 }
19681991 check ( "10" , Some ( 10 ) ) ;
@@ -1980,7 +2003,8 @@ mod bigint_tests {
19802003 BigInt :: new( Minus , ~[ 1 , 1 , 1 ] ) ) ;
19812004 assert ! ( -BigInt :: new( Minus , ~[ 1 , 1 , 1 ] ) ==
19822005 BigInt :: new( Plus , ~[ 1 , 1 , 1 ] ) ) ;
1983- assert_eq ! ( -Zero :: zero:: <BigInt >( ) , Zero :: zero:: <BigInt >( ) ) ;
2006+ let zero: BigInt = Zero :: zero ( ) ;
2007+ assert_eq ! ( -zero, zero) ;
19842008 }
19852009}
19862010
@@ -1992,16 +2016,16 @@ mod bench {
19922016 use extra:: test:: BenchHarness ;
19932017
19942018 fn factorial ( n : uint ) -> BigUint {
1995- let mut f = One :: one :: < BigUint > ( ) ;
2019+ let mut f: BigUint = One :: one ( ) ;
19962020 for i in iterator:: range_inclusive ( 1 , n) {
19972021 f = f * BigUint :: from_uint ( i) ;
19982022 }
19992023 f
20002024 }
20012025
20022026 fn fib ( n : uint ) -> BigUint {
2003- let mut f0 = Zero :: zero :: < BigUint > ( ) ;
2004- let mut f1 = One :: one :: < BigUint > ( ) ;
2027+ let mut f0: BigUint = Zero :: zero ( ) ;
2028+ let mut f1: BigUint = One :: one ( ) ;
20052029 for _ in range ( 0 , n) {
20062030 let f2 = f0 + f1;
20072031 f0 = util:: replace ( & mut f1, f2) ;
0 commit comments