Skip to content

Commit

Permalink
Merge #335
Browse files Browse the repository at this point in the history
335: Clean up some warnings r=cuviper a=cuviper
  • Loading branch information
bors[bot] committed Sep 22, 2017
2 parents 4896746 + 2f8f952 commit 741a5a6
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 53 deletions.
1 change: 0 additions & 1 deletion bigint/src/algorithms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ pub fn div_rem_digit(mut a: BigUint, b: BigDigit) -> (BigUint, BigDigit) {
}

// Only for the Add impl:
#[must_use]
#[inline]
pub fn __add2(a: &mut [BigDigit], b: &[BigDigit]) -> BigDigit {
debug_assert!(a.len() >= b.len());
Expand Down
2 changes: 1 addition & 1 deletion bigint/src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ fn twos_complement<'a, I>(digits: I)
where I: IntoIterator<Item = &'a mut u8>
{
let mut carry = true;
for mut d in digits {
for d in digits {
*d = d.not();
if carry {
*d = d.wrapping_add(1);
Expand Down
2 changes: 2 additions & 0 deletions bigint/src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unknown_lints)] // older rustc doesn't know `unused_macros`
#![allow(unused_macros)]

macro_rules! forward_val_val_binop {
(impl $imp:ident for $res:ty, $method:ident) => {
Expand Down
18 changes: 9 additions & 9 deletions traits/src/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ for_each_tuple!(bounded_tuple);
bounded_impl!(f64, f64::MIN, f64::MAX);


macro_rules! test_wrapping_bounded {
($($t:ty)+) => {
$(
assert_eq!(Wrapping::<$t>::min_value().0, <$t>::min_value());
assert_eq!(Wrapping::<$t>::max_value().0, <$t>::max_value());
)+
};
}

#[test]
fn wrapping_bounded() {
macro_rules! test_wrapping_bounded {
($($t:ty)+) => {
$(
assert_eq!(Wrapping::<$t>::min_value().0, <$t>::min_value());
assert_eq!(Wrapping::<$t>::max_value().0, <$t>::max_value());
)+
};
}

test_wrapping_bounded!(usize u8 u16 u32 u64 isize i8 i16 i32 i64);
}

Expand Down
42 changes: 21 additions & 21 deletions traits/src/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,29 +466,29 @@ fn to_primitive_float() {
assert!((f64::NAN).to_f32().map_or(false, |f| f.is_nan()));
}

macro_rules! test_wrapping_to_primitive {
($($t:ty)+) => {
$({
let i: $t = 0;
let w = Wrapping(i);
assert_eq!(i.to_u8(), w.to_u8());
assert_eq!(i.to_u16(), w.to_u16());
assert_eq!(i.to_u32(), w.to_u32());
assert_eq!(i.to_u64(), w.to_u64());
assert_eq!(i.to_usize(), w.to_usize());
assert_eq!(i.to_i8(), w.to_i8());
assert_eq!(i.to_i16(), w.to_i16());
assert_eq!(i.to_i32(), w.to_i32());
assert_eq!(i.to_i64(), w.to_i64());
assert_eq!(i.to_isize(), w.to_isize());
assert_eq!(i.to_f32(), w.to_f32());
assert_eq!(i.to_f64(), w.to_f64());
})+
};
}

#[test]
fn wrapping_to_primitive() {
macro_rules! test_wrapping_to_primitive {
($($t:ty)+) => {
$({
let i: $t = 0;
let w = Wrapping(i);
assert_eq!(i.to_u8(), w.to_u8());
assert_eq!(i.to_u16(), w.to_u16());
assert_eq!(i.to_u32(), w.to_u32());
assert_eq!(i.to_u64(), w.to_u64());
assert_eq!(i.to_usize(), w.to_usize());
assert_eq!(i.to_i8(), w.to_i8());
assert_eq!(i.to_i16(), w.to_i16());
assert_eq!(i.to_i32(), w.to_i32());
assert_eq!(i.to_i64(), w.to_i64());
assert_eq!(i.to_isize(), w.to_isize());
assert_eq!(i.to_f32(), w.to_f32());
assert_eq!(i.to_f64(), w.to_f64());
})+
};
}

test_wrapping_to_primitive!(usize u8 u16 u32 u64 isize i8 i16 i32 i64);
}

Expand Down
22 changes: 11 additions & 11 deletions traits/src/identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,19 @@ impl<T: One> One for Wrapping<T> where Wrapping<T>: Mul<Output=Wrapping<T>> {
#[inline(always)] pub fn one<T: One>() -> T { One::one() }


macro_rules! test_wrapping_identities {
($($t:ty)+) => {
$(
assert_eq!(zero::<$t>(), zero::<Wrapping<$t>>().0);
assert_eq!(one::<$t>(), one::<Wrapping<$t>>().0);
assert_eq!((0 as $t).is_zero(), Wrapping(0 as $t).is_zero());
assert_eq!((1 as $t).is_zero(), Wrapping(1 as $t).is_zero());
)+
};
}

#[test]
fn wrapping_identities() {
macro_rules! test_wrapping_identities {
($($t:ty)+) => {
$(
assert_eq!(zero::<$t>(), zero::<Wrapping<$t>>().0);
assert_eq!(one::<$t>(), one::<Wrapping<$t>>().0);
assert_eq!((0 as $t).is_zero(), Wrapping(0 as $t).is_zero());
assert_eq!((1 as $t).is_zero(), Wrapping(1 as $t).is_zero());
)+
};
}

test_wrapping_identities!(isize i8 i16 i32 i64 usize u8 u16 u32 u64);
}

Expand Down
22 changes: 12 additions & 10 deletions traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,24 +361,26 @@ fn from_str_radix_unwrap() {
assert_eq!(f, 0.0);
}

macro_rules! test_wrapping_from_str_radix {
($($t:ty)+) => {
$(
for &(s, r) in &[("42", 10), ("42", 2), ("-13.0", 10), ("foo", 10)] {
let w = Wrapping::<$t>::from_str_radix(s, r).map(|w| w.0);
assert_eq!(w, <$t as Num>::from_str_radix(s, r));
}
)+
};
}
#[test]
fn wrapping_is_num() {
fn require_num<T: Num>(_: &T) {}
require_num(&Wrapping(42_u32));
require_num(&Wrapping(-42));
}

#[test]
fn wrapping_from_str_radix() {
macro_rules! test_wrapping_from_str_radix {
($($t:ty)+) => {
$(
for &(s, r) in &[("42", 10), ("42", 2), ("-13.0", 10), ("foo", 10)] {
let w = Wrapping::<$t>::from_str_radix(s, r).map(|w| w.0);
assert_eq!(w, <$t as Num>::from_str_radix(s, r));
}
)+
};
}

test_wrapping_from_str_radix!(usize u8 u16 u32 u64 isize i8 i16 i32 i64);
}

Expand Down

0 comments on commit 741a5a6

Please sign in to comment.