Skip to content

Commit fe2908d

Browse files
bors[bot]HactarCEcuviper
authored
Merge #133
133: Fix promotion of negative isize r=cuviper a=HactarCE This fixes #132. Co-authored-by: Hactar <[email protected]> Co-authored-by: Josh Stone <[email protected]>
2 parents 573681d + aae704e commit fe2908d

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

src/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ macro_rules! promote_signed_scalars {
340340
macro_rules! promote_signed_scalars_assign {
341341
(impl $imp:ident for $res:ty, $method:ident) => {
342342
promote_scalars_assign!(impl $imp<i32> for $res, $method, i8, i16);
343-
promote_scalars_assign!(impl $imp<UsizePromotion> for $res, $method, isize);
343+
promote_scalars_assign!(impl $imp<IsizePromotion> for $res, $method, isize);
344344
}
345345
}
346346

tests/bigint_scalar.rs

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fn test_scalar_add() {
1515
fn check(x: &BigInt, y: &BigInt, z: &BigInt) {
1616
let (x, y, z) = (x.clone(), y.clone(), z.clone());
1717
assert_signed_scalar_op!(x + y == z);
18+
assert_signed_scalar_assign_op!(x += y == z);
1819
}
1920

2021
for elm in SUM_TRIPLES.iter() {
@@ -40,6 +41,7 @@ fn test_scalar_sub() {
4041
fn check(x: &BigInt, y: &BigInt, z: &BigInt) {
4142
let (x, y, z) = (x.clone(), y.clone(), z.clone());
4243
assert_signed_scalar_op!(x - y == z);
44+
assert_signed_scalar_assign_op!(x -= y == z);
4345
}
4446

4547
for elm in SUM_TRIPLES.iter() {
@@ -65,6 +67,7 @@ fn test_scalar_mul() {
6567
fn check(x: &BigInt, y: &BigInt, z: &BigInt) {
6668
let (x, y, z) = (x.clone(), y.clone(), z.clone());
6769
assert_signed_scalar_op!(x * y == z);
70+
assert_signed_scalar_assign_op!(x *= y == z);
6871
}
6972

7073
for elm in MUL_TRIPLES.iter() {
@@ -99,10 +102,14 @@ fn test_scalar_div_rem() {
99102
let (a, ans_q, ans_r) = (a.clone(), ans_q.clone(), ans_r.clone());
100103
assert_signed_scalar_op!(a / b == ans_q);
101104
assert_signed_scalar_op!(a % b == ans_r);
105+
assert_signed_scalar_assign_op!(a /= b == ans_q);
106+
assert_signed_scalar_assign_op!(a %= b == ans_r);
102107

103108
let nb = -b;
104109
assert_signed_scalar_op!(a / nb == -ans_q.clone());
105110
assert_signed_scalar_op!(a % nb == ans_r);
111+
assert_signed_scalar_assign_op!(a /= nb == -ans_q.clone());
112+
assert_signed_scalar_assign_op!(a %= nb == ans_r);
106113
}
107114

108115
fn check(a: &BigInt, b: u32, q: &BigInt, r: &BigInt) {

tests/biguint_scalar.rs

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fn test_scalar_add() {
1212
fn check(x: &BigUint, y: &BigUint, z: &BigUint) {
1313
let (x, y, z) = (x.clone(), y.clone(), z.clone());
1414
assert_unsigned_scalar_op!(x + y == z);
15+
assert_unsigned_scalar_assign_op!(x += y == z);
1516
}
1617

1718
for elm in SUM_TRIPLES.iter() {
@@ -30,6 +31,7 @@ fn test_scalar_sub() {
3031
fn check(x: &BigUint, y: &BigUint, z: &BigUint) {
3132
let (x, y, z) = (x.clone(), y.clone(), z.clone());
3233
assert_unsigned_scalar_op!(x - y == z);
34+
assert_unsigned_scalar_assign_op!(x -= y == z);
3335
}
3436

3537
for elm in SUM_TRIPLES.iter() {
@@ -48,6 +50,7 @@ fn test_scalar_mul() {
4850
fn check(x: &BigUint, y: &BigUint, z: &BigUint) {
4951
let (x, y, z) = (x.clone(), y.clone(), z.clone());
5052
assert_unsigned_scalar_op!(x * y == z);
53+
assert_unsigned_scalar_assign_op!(x *= y == z);
5154
}
5255

5356
for elm in MUL_TRIPLES.iter() {
@@ -73,6 +76,8 @@ fn test_scalar_div_rem() {
7376
let (x, y, z, r) = (x.clone(), y.clone(), z.clone(), r.clone());
7477
assert_unsigned_scalar_op!(x / y == z);
7578
assert_unsigned_scalar_op!(x % y == r);
79+
assert_unsigned_scalar_assign_op!(x /= y == z);
80+
assert_unsigned_scalar_assign_op!(x %= y == r);
7681
}
7782

7883
for elm in MUL_TRIPLES.iter() {
@@ -101,6 +106,8 @@ fn test_scalar_div_rem() {
101106
check(&a, &b, &c, &d);
102107
assert_unsigned_scalar_op!(a / b == c);
103108
assert_unsigned_scalar_op!(a % b == d);
109+
assert_unsigned_scalar_assign_op!(a /= b == c);
110+
assert_unsigned_scalar_assign_op!(a %= b == d);
104111
}
105112
}
106113
}

tests/macros/mod.rs

+27
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,30 @@ macro_rules! assert_signed_scalar_op {
4949
$left $op $right == $expected);
5050
};
5151
}
52+
53+
/// Assert that an op works for scalar right
54+
macro_rules! assert_scalar_assign_op {
55+
(($($to:ident),*) $left:ident $op:tt $right:ident == $expected:expr) => {
56+
$(
57+
if let Some(right) = $right.$to() {
58+
let mut left = $left.clone();
59+
assert_eq!({ left $op right; left}, $expected);
60+
}
61+
)*
62+
};
63+
}
64+
65+
macro_rules! assert_unsigned_scalar_assign_op {
66+
($left:ident $op:tt $right:ident == $expected:expr) => {
67+
assert_scalar_assign_op!((to_u8, to_u16, to_u32, to_u64, to_usize, to_u128)
68+
$left $op $right == $expected);
69+
};
70+
}
71+
72+
macro_rules! assert_signed_scalar_assign_op {
73+
($left:ident $op:tt $right:ident == $expected:expr) => {
74+
assert_scalar_assign_op!((to_u8, to_u16, to_u32, to_u64, to_usize, to_u128,
75+
to_i8, to_i16, to_i32, to_i64, to_isize, to_i128)
76+
$left $op $right == $expected);
77+
};
78+
}

0 commit comments

Comments
 (0)