Make new code work on rustc-1.8.0
- Don't apply attributes to statements (1.12.0) - Don't use checked_abs (1.13.0)
This commit is contained in:
parent
2a3cd41820
commit
1fb03ca18a
|
@ -28,6 +28,9 @@ use biguint;
|
|||
use biguint::to_str_radix_reversed;
|
||||
use biguint::BigUint;
|
||||
|
||||
use UsizePromotion;
|
||||
use IsizePromotion;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "tests/bigint.rs"]
|
||||
mod bigint_tests;
|
||||
|
@ -301,17 +304,19 @@ impl Signed for BigInt {
|
|||
|
||||
// A convenience method for getting the absolute value of an i32 in a u32.
|
||||
fn i32_abs_as_u32(a: i32) -> u32 {
|
||||
match a.checked_abs() {
|
||||
Some(x) => x as u32,
|
||||
None => a as u32
|
||||
if a == i32::min_value() {
|
||||
a as u32
|
||||
} else {
|
||||
a.abs() as u32
|
||||
}
|
||||
}
|
||||
|
||||
// A convenience method for getting the absolute value of an i64 in a u64.
|
||||
fn i64_abs_as_u64(a: i64) -> u64 {
|
||||
match a.checked_abs() {
|
||||
Some(x) => x as u64,
|
||||
None => a as u64
|
||||
if a == i64::min_value() {
|
||||
a as u64
|
||||
} else {
|
||||
a.abs() as u64
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,8 @@ use self::algorithms::{__add2, add2, sub2, sub2rev};
|
|||
use self::algorithms::{biguint_shl, biguint_shr};
|
||||
use self::algorithms::{cmp_slice, fls, ilog2};
|
||||
|
||||
use UsizePromotion;
|
||||
|
||||
use ParseBigIntError;
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -88,6 +88,16 @@ use std::error::Error;
|
|||
use std::num::ParseIntError;
|
||||
use std::fmt;
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
type UsizePromotion = u32;
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
type UsizePromotion = u64;
|
||||
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
type IsizePromotion = i32;
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
type IsizePromotion = i64;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum ParseBigIntError {
|
||||
ParseInt(ParseIntError),
|
||||
|
|
|
@ -210,35 +210,17 @@ macro_rules! promote_scalars {
|
|||
}
|
||||
}
|
||||
|
||||
macro_rules! promote_unsigned_scalars_to_u32 {
|
||||
macro_rules! promote_unsigned_scalars {
|
||||
(impl $imp:ident for $res:ty, $method:ident) => {
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
promote_scalars!(impl $imp<u32> for $res, $method, u8, u16, usize);
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
promote_scalars!(impl $imp<u32> for $res, $method, u8, u16);
|
||||
promote_scalars!(impl $imp<UsizePromotion> for $res, $method, usize);
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! promote_unsigned_scalars_to_u64 {
|
||||
macro_rules! promote_signed_scalars {
|
||||
(impl $imp:ident for $res:ty, $method:ident) => {
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
promote_scalars!(impl $imp<u64> for $res, $method, usize);
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! promote_signed_scalars_to_i32 {
|
||||
(impl $imp:ident for $res:ty, $method:ident) => {
|
||||
#[cfg(target_pointer_width = "32")]
|
||||
promote_scalars!(impl $imp<i32> for $res, $method, i8, i16, isize);
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
promote_scalars!(impl $imp<i32> for $res, $method, i8, i16);
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! promote_signed_scalars_to_i64 {
|
||||
(impl $imp:ident for $res:ty, $method:ident) => {
|
||||
#[cfg(target_pointer_width = "64")]
|
||||
promote_scalars!(impl $imp<i64> for $res, $method, isize);
|
||||
promote_scalars!(impl $imp<IsizePromotion> for $res, $method, isize);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -284,20 +266,6 @@ macro_rules! forward_all_scalar_binop_to_val_val_commutative {
|
|||
}
|
||||
}
|
||||
|
||||
macro_rules! promote_unsigned_scalars {
|
||||
(impl $imp:ident for $res:ty, $method:ident) => {
|
||||
promote_unsigned_scalars_to_u32!(impl $imp for $res, $method);
|
||||
promote_unsigned_scalars_to_u64!(impl $imp for $res, $method);
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! promote_signed_scalars {
|
||||
(impl $imp:ident for $res:ty, $method:ident) => {
|
||||
promote_signed_scalars_to_i32!(impl $imp for $res, $method);
|
||||
promote_signed_scalars_to_i64!(impl $imp for $res, $method);
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! promote_all_scalars {
|
||||
(impl $imp:ident for $res:ty, $method:ident) => {
|
||||
promote_unsigned_scalars!(impl $imp for $res, $method);
|
||||
|
|
Loading…
Reference in New Issue