Skip to content

Commit 5b3458b

Browse files
Also allow Wrapping<T> op= &Wrapping<T>
Similarly to the built-in numeric types, Wrapping<T> supports reference arguments for unary and binary operators, but not for the assignment versions of binary operators. This commit fixes that.
1 parent 5960968 commit 5b3458b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/libcore/num/wrapping.rs

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ macro_rules! sh_impl_signed {
3535
*self = *self << other;
3636
}
3737
}
38+
forward_ref_op_assign! { impl ShlAssign, shl_assign for Wrapping<$t>, $f }
3839

3940
#[stable(feature = "rust1", since = "1.0.0")]
4041
impl Shr<$f> for Wrapping<$t> {
@@ -57,6 +58,7 @@ macro_rules! sh_impl_signed {
5758
*self = *self >> other;
5859
}
5960
}
61+
forward_ref_op_assign! { impl ShrAssign, shr_assign for Wrapping<$t>, $f }
6062
)
6163
}
6264

@@ -79,6 +81,7 @@ macro_rules! sh_impl_unsigned {
7981
*self = *self << other;
8082
}
8183
}
84+
forward_ref_op_assign! { impl ShlAssign, shl_assign for Wrapping<$t>, $f }
8285

8386
#[stable(feature = "rust1", since = "1.0.0")]
8487
impl Shr<$f> for Wrapping<$t> {
@@ -97,6 +100,7 @@ macro_rules! sh_impl_unsigned {
97100
*self = *self >> other;
98101
}
99102
}
103+
forward_ref_op_assign! { impl ShrAssign, shr_assign for Wrapping<$t>, $f }
100104
)
101105
}
102106

@@ -141,6 +145,7 @@ macro_rules! wrapping_impl {
141145
*self = *self + other;
142146
}
143147
}
148+
forward_ref_op_assign! { impl AddAssign, add_assign for Wrapping<$t>, Wrapping<$t> }
144149

145150
#[stable(feature = "rust1", since = "1.0.0")]
146151
impl Sub for Wrapping<$t> {
@@ -161,6 +166,7 @@ macro_rules! wrapping_impl {
161166
*self = *self - other;
162167
}
163168
}
169+
forward_ref_op_assign! { impl SubAssign, sub_assign for Wrapping<$t>, Wrapping<$t> }
164170

165171
#[stable(feature = "rust1", since = "1.0.0")]
166172
impl Mul for Wrapping<$t> {
@@ -181,6 +187,7 @@ macro_rules! wrapping_impl {
181187
*self = *self * other;
182188
}
183189
}
190+
forward_ref_op_assign! { impl MulAssign, mul_assign for Wrapping<$t>, Wrapping<$t> }
184191

185192
#[stable(feature = "wrapping_div", since = "1.3.0")]
186193
impl Div for Wrapping<$t> {
@@ -201,6 +208,7 @@ macro_rules! wrapping_impl {
201208
*self = *self / other;
202209
}
203210
}
211+
forward_ref_op_assign! { impl DivAssign, div_assign for Wrapping<$t>, Wrapping<$t> }
204212

205213
#[stable(feature = "wrapping_impls", since = "1.7.0")]
206214
impl Rem for Wrapping<$t> {
@@ -221,6 +229,7 @@ macro_rules! wrapping_impl {
221229
*self = *self % other;
222230
}
223231
}
232+
forward_ref_op_assign! { impl RemAssign, rem_assign for Wrapping<$t>, Wrapping<$t> }
224233

225234
#[stable(feature = "rust1", since = "1.0.0")]
226235
impl Not for Wrapping<$t> {
@@ -253,6 +262,7 @@ macro_rules! wrapping_impl {
253262
*self = *self ^ other;
254263
}
255264
}
265+
forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Wrapping<$t>, Wrapping<$t> }
256266

257267
#[stable(feature = "rust1", since = "1.0.0")]
258268
impl BitOr for Wrapping<$t> {
@@ -273,6 +283,7 @@ macro_rules! wrapping_impl {
273283
*self = *self | other;
274284
}
275285
}
286+
forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Wrapping<$t>, Wrapping<$t> }
276287

277288
#[stable(feature = "rust1", since = "1.0.0")]
278289
impl BitAnd for Wrapping<$t> {
@@ -293,6 +304,7 @@ macro_rules! wrapping_impl {
293304
*self = *self & other;
294305
}
295306
}
307+
forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Wrapping<$t>, Wrapping<$t> }
296308

297309
#[stable(feature = "wrapping_neg", since = "1.10.0")]
298310
impl Neg for Wrapping<$t> {

0 commit comments

Comments
 (0)