Change:
The other day I noticed that only implements and co. for , which contradicts that without the shift amount can be any type. So, I think it may be useful to create tests which use macros to shove together all the types we expect to have impls for and check that we're consistent there. What I've noticed: For every operation three extra impls are , with the combinations of single-level references on both sides, e.g. , , for . Assignment ops do the same as the above, with only one extra impl, e.g. for . , , , , exist for all int and float types with themselves , , exist for all int types and bool and allow any integer type for both the left and the right side exists for all ints and floats exists for all ints and bool should mimic all of the above, where references are of the form and not . Like, I wouldn't be surprised if rearranging some macros might add or remove impls for these and adding comprehensive tests might help make sure we covered everything. <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
This seems like a simple but useful task, I will try to finish it.
I am reformulating the task to make sure it is clear (to myself at least) : Create tests using a set of macros to check that every numerical instances of for the following operations are implemented for every combination of numerical instances (, , ...) : with : * having the integer and float types with themselves, ¤ having the integer and bool types with themselves, having the integer and float types with themselves, and Am I correct ? How does this relate to ?(e.g. is it possible to bypass the bug and still implement the test ? I could not see from the issue if a solution had been found)
claim isn't implemented for and /. So this is probably only useful for integer types.
This doesn't actually fix the issue; it should be tested for all types, not just .
Hi ! Are you or anyone else working on adding the missed tests?
They're free for anyone to implement right now!
Nope, not right now. Feel free to take over. It should be pretty similar to , just add the missing types (bool, fp) and operators (bit wise operators).
Thank you very much and , I'll send a PR.
unassign
claim I'll try to get a PR in by next weekend, If nothing happens past that I'm afraid I may have been too busy so [anyone] feel free to overtake :smile:
claim
Hi, are you still working on this issue
I'm sorry, I couldn't do it. Please feel free to reassign this.
No worries release-assignment

Discussion:
} } } <ins> forward_ref_binop! { impl Shl, shl for Wrapping<$t>, $f, #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] } </ins> #[stable(feature = "op_assign_traits", since = "1.8.0")] impl ShlAssign<$f> for Wrapping<$t> {

} } } <ins> forward_ref_binop! { impl Shr, shr for Wrapping<$t>, $f, #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] } </ins> #[stable(feature = "op_assign_traits", since = "1.8.0")] impl ShrAssign<$f> for Wrapping<$t> {

Wrapping(self.0.wrapping_shl((other & self::shift_max::$t as $f) as u32)) } } <ins> forward_ref_binop! { impl Shl, shl for Wrapping<$t>, $f, #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] } </ins> #[stable(feature = "op_assign_traits", since = "1.8.0")] impl ShlAssign<$f> for Wrapping<$t> {

Wrapping(self.0.wrapping_shr((other & self::shift_max::$t as $f) as u32)) } } <ins> forward_ref_binop! { impl Shr, shr for Wrapping<$t>, $f, #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] } </ins> #[stable(feature = "op_assign_traits", since = "1.8.0")] impl ShrAssign<$f> for Wrapping<$t> {

<ins> // run-pass use std::num::Wrapping; macro_rules! wrapping_operation { ($result:expr, $lhs:ident $op:tt $rhs:expr) => { assert_eq!($result, $lhs $op $rhs); assert_eq!($result, &$lhs $op $rhs); assert_eq!($result, $lhs $op &$rhs); assert_eq!($result, &$lhs $op &$rhs); }; ($result:expr, $op:tt $expr:expr) => { assert_eq!($result, $op $expr); assert_eq!($result, $op &$expr); }; } macro_rules! wrapping_assignment { ($result:expr, $lhs:ident $op:tt $rhs:expr) => { let mut lhs1 = $lhs; lhs1 $op $rhs; assert_eq!($result, lhs1); let mut lhs2 = $lhs; lhs2 $op &$rhs; assert_eq!($result, lhs2); }; } macro_rules! wrapping_test { ($type:ty, $min:expr, $max:expr) => { let zero: Wrapping<$type> = Wrapping(0); let one: Wrapping<$type> = Wrapping(1); let min: Wrapping<$type> = Wrapping($min); let max: Wrapping<$type> = Wrapping($max); wrapping_operation!(min, max + one); wrapping_assignment!(min, max += one); wrapping_operation!(max, min - one); wrapping_assignment!(max, min -= one); wrapping_operation!(max, max * one); wrapping_assignment!(max, max *= one); wrapping_operation!(max, max / one); wrapping_assignment!(max, max /= one); wrapping_operation!(zero, max % one); wrapping_assignment!(zero, max %= one); wrapping_operation!(zero, zero & max); wrapping_assignment!(zero, zero &= max); wrapping_operation!(max, zero | max); wrapping_assignment!(max, zero |= max); wrapping_operation!(zero, max ^ max); wrapping_assignment!(zero, max ^= max); wrapping_operation!(zero, zero << 1usize); wrapping_assignment!(zero, zero <<= 1usize); wrapping_operation!(zero, zero >> 1usize); wrapping_assignment!(zero, zero >>= 1usize); wrapping_operation!(zero, -zero); wrapping_operation!(max, !min); }; } fn main() { wrapping_test!(i8, std::i8::MIN, std::i8::MAX); wrapping_test!(i16, std::i16::MIN, std::i16::MAX); wrapping_test!(i32, std::i32::MIN, std::i32::MAX); wrapping_test!(i64, std::i64::MIN, std::i64::MAX); #[cfg(not(target_os = "emscripten"))] wrapping_test!(i128, std::i128::MIN, std::i128::MAX); wrapping_test!(isize, std::isize::MIN, std::isize::MAX); wrapping_test!(u8, std::u8::MIN, std::u8::MAX); wrapping_test!(u16, std::u16::MIN, std::u16::MAX); wrapping_test!(u32, std::u32::MIN, std::u32::MAX); wrapping_test!(u64, std::u64::MIN, std::u64::MAX); #[cfg(not(target_os = "emscripten"))] wrapping_test!(u128, std::u128::MIN, std::u128::MAX); wrapping_test!(usize, std::usize::MIN, std::usize::MAX); } </ins>