@@ -16,6 +16,9 @@ A BigUint is represented as an array of BigDigits.
16
16
A BigInt is a combination of BigUint and Sign.
17
17
*/
18
18
19
+ #[ deny( vecs_implicitly_copyable) ] ;
20
+ #[ deny( deprecated_mutable_fields) ] ;
21
+
19
22
use core:: cmp:: { Eq , Ord , TotalEq , TotalOrd , Ordering , Less , Equal , Greater } ;
20
23
use core:: num:: { IntConvertible , Zero , One , ToStrRadix , FromStrRadix } ;
21
24
use core:: * ;
@@ -355,16 +358,24 @@ impl Integer for BigUint {
355
358
let mut ( d0, d_unit, b_unit) = div_estimate ( & m, & b, n) ;
356
359
let mut prod = b * d0;
357
360
while prod > m {
358
- d0 -= d_unit;
359
- prod -= b_unit;
361
+ // FIXME(#6050): overloaded operators force moves with generic types
362
+ // d0 -= d_unit
363
+ d0 = d0 - d_unit;
364
+ // FIXME(#6050): overloaded operators force moves with generic types
365
+ // prod = prod - b_unit;
366
+ prod = prod - b_unit
360
367
}
361
368
if d0. is_zero ( ) {
362
369
n = 2 ;
363
370
loop ;
364
371
}
365
372
n = 1 ;
366
- d += d0;
367
- m -= prod;
373
+ // FIXME(#6102): Assignment operator for BigInt causes ICE
374
+ // d += d0;
375
+ d = d + d0;
376
+ // FIXME(#6102): Assignment operator for BigInt causes ICE
377
+ // m -= prod;
378
+ m = m - prod;
368
379
}
369
380
return ( d, m) ;
370
381
}
@@ -411,7 +422,7 @@ impl Integer for BigUint {
411
422
#[ inline( always) ]
412
423
fn gcd ( & self , other : & BigUint ) -> BigUint {
413
424
// Use Euclid's algorithm
414
- let mut m = * self , n = * other;
425
+ let mut m = copy * self , n = copy * other;
415
426
while !m. is_zero ( ) {
416
427
let temp = m;
417
428
m = n % temp;
@@ -547,14 +558,18 @@ impl BigUint {
547
558
loop {
548
559
let start = uint:: max ( end, unit_len) - unit_len;
549
560
match uint:: parse_bytes ( vec:: slice ( buf, start, end) , radix) {
550
- Some ( d) => n += BigUint :: from_uint ( d) * power,
561
+ // FIXME(#6102): Assignment operator for BigInt causes ICE
562
+ // Some(d) => n += BigUint::from_uint(d) * power,
563
+ Some ( d) => n = n + BigUint :: from_uint ( d) * power,
551
564
None => return None
552
565
}
553
566
if end <= unit_len {
554
567
return Some ( n) ;
555
568
}
556
569
end -= unit_len;
557
- power *= base_num;
570
+ // FIXME(#6050): overloaded operators force moves with generic types
571
+ // power *= base_num;
572
+ power = power * base_num;
558
573
}
559
574
}
560
575
@@ -569,15 +584,15 @@ impl BigUint {
569
584
}
570
585
571
586
#[ inline( always) ]
572
- priv fn shl_unit ( self , n_unit : uint ) -> BigUint {
573
- if n_unit == 0 || self . is_zero ( ) { return self ; }
587
+ priv fn shl_unit ( & self , n_unit : uint ) -> BigUint {
588
+ if n_unit == 0 || self . is_zero ( ) { return copy * self ; }
574
589
575
590
return BigUint :: new ( vec:: from_elem ( n_unit, 0 ) + self . data ) ;
576
591
}
577
592
578
593
#[ inline( always) ]
579
- priv fn shl_bits ( self , n_bits : uint ) -> BigUint {
580
- if n_bits == 0 || self . is_zero ( ) { return self ; }
594
+ priv fn shl_bits ( & self , n_bits : uint ) -> BigUint {
595
+ if n_bits == 0 || self . is_zero ( ) { return copy * self ; }
581
596
582
597
let mut carry = 0 ;
583
598
let shifted = do vec:: map ( self . data ) |elem| {
@@ -592,23 +607,23 @@ impl BigUint {
592
607
}
593
608
594
609
#[ inline( always) ]
595
- priv fn shr_unit ( self , n_unit : uint ) -> BigUint {
596
- if n_unit == 0 { return self ; }
610
+ priv fn shr_unit ( & self , n_unit : uint ) -> BigUint {
611
+ if n_unit == 0 { return copy * self ; }
597
612
if self . data . len ( ) < n_unit { return Zero :: zero ( ) ; }
598
613
return BigUint :: from_slice (
599
614
vec:: slice ( self . data , n_unit, self . data . len ( ) )
600
615
) ;
601
616
}
602
617
603
618
#[ inline( always) ]
604
- priv fn shr_bits ( self , n_bits : uint ) -> BigUint {
605
- if n_bits == 0 || self . data . is_empty ( ) { return self ; }
619
+ priv fn shr_bits ( & self , n_bits : uint ) -> BigUint {
620
+ if n_bits == 0 || self . data . is_empty ( ) { return copy * self ; }
606
621
607
622
let mut borrow = 0 ;
608
623
let mut shifted = ~[ ] ;
609
624
for self . data. each_reverse |elem| {
610
625
shifted = ~[ ( * elem >> n_bits) | borrow] + shifted;
611
- borrow = * elem << ( uint :: bits - n_bits) ;
626
+ borrow = * elem << ( BigDigit :: bits - n_bits) ;
612
627
}
613
628
return BigUint :: new ( shifted) ;
614
629
}
@@ -1070,7 +1085,7 @@ pub impl BigInt {
1070
1085
start = 1;
1071
1086
}
1072
1087
return BigUint::parse_bytes(vec::slice(buf, start, buf.len()), radix)
1073
- .map (|bu| BigInt::from_biguint(sign, * bu));
1088
+ .map_consume (|bu| BigInt::from_biguint(sign, bu));
1074
1089
}
1075
1090
1076
1091
#[inline(always)]
@@ -1198,6 +1213,7 @@ mod biguint_tests {
1198
1213
check ( ~[ 1 << 2 ] , 2 , ~[ 1 ] ) ;
1199
1214
check ( ~[ 1 , 2 ] , 3 , ~[ 1 << ( BigDigit :: bits - 2 ) ] ) ;
1200
1215
check ( ~[ 1 , 1 , 2 ] , 3 + BigDigit :: bits, ~[ 1 << ( BigDigit :: bits - 2 ) ] ) ;
1216
+ check ( ~[ 0 , 1 ] , 1 , ~[ 0x80000000 ] ) ;
1201
1217
test_shr_bits ( ) ;
1202
1218
1203
1219
#[ cfg( target_arch = "x86_64" ) ]
@@ -1376,10 +1392,10 @@ mod biguint_tests {
1376
1392
let c = BigUint :: from_slice ( cVec) ;
1377
1393
1378
1394
if !a. is_zero ( ) {
1379
- assert ! ( c. quot_rem( & a) == ( b, Zero :: zero( ) ) ) ;
1395
+ assert ! ( c. quot_rem( & a) == ( copy b, Zero :: zero( ) ) ) ;
1380
1396
}
1381
1397
if !b. is_zero ( ) {
1382
- assert ! ( c. quot_rem( & b) == ( a, Zero :: zero( ) ) ) ;
1398
+ assert ! ( c. quot_rem( & b) == ( copy a, Zero :: zero( ) ) ) ;
1383
1399
}
1384
1400
}
1385
1401
@@ -1503,7 +1519,7 @@ mod biguint_tests {
1503
1519
let & ( n, rs) = num_pair;
1504
1520
for rs. each |str_pair| {
1505
1521
let & ( radix, str) = str_pair;
1506
- assert_eq ! ( Some ( n ) , FromStrRadix :: from_str_radix( str , radix) ) ;
1522
+ assert_eq ! ( & n , & FromStrRadix :: from_str_radix( str , radix) . get ( ) ) ;
1507
1523
}
1508
1524
}
1509
1525
@@ -1517,7 +1533,9 @@ mod biguint_tests {
1517
1533
fn factor(n: uint) -> BigUint {
1518
1534
let mut f= One::one::<BigUint>();
1519
1535
for uint::range(2, n + 1) |i| {
1520
- f *= BigUint::from_uint(i);
1536
+ // FIXME(#6102): Assignment operator for BigInt causes ICE
1537
+ // f *= BigUint::from_uint(i);
1538
+ f = f * BigUint::from_uint(i);
1521
1539
}
1522
1540
return f;
1523
1541
}
0 commit comments