Skip to content

Commit e3c972e

Browse files
authored
Rollup merge of #93208 - kellerkindt:wrapping_int_assign_impl, r=m-ou-se
Impl {Add,Sub,Mul,Div,Rem,BitXor,BitOr,BitAnd}Assign<$t> for Wrapping<$t> for rust 1.60.0 Tracking issue #93204 This is about adding basic integer operations to the `Wrapping` type: ```rust let mut value = Wrapping(2u8); value += 3u8; value -= 1u8; value *= 2u8; value /= 2u8; value %= 2u8; value ^= 255u8; value |= 123u8; value &= 2u8; ``` Because this adds stable impls on a stable type, it runs into the following issue if an `#[unstable(...)]` attribute is used: ``` an `#[unstable]` annotation here has no effect note: see issue #55436 <#55436> for more information ``` This means - if I understood this correctly - the new impls have to be stabilized instantly. Which in turn means, this PR has to kick of an FCP on the tracking issue as well? This impl is analog to 1c0dc18 #92356 for the `Saturating` type ``@dtolnay`` ``@Mark-Simulacrum``
2 parents 8219ad4 + 14ff58c commit e3c972e

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

library/core/src/num/wrapping.rs

+80
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,16 @@ macro_rules! wrapping_impl {
239239
}
240240
forward_ref_op_assign! { impl const AddAssign, add_assign for Wrapping<$t>, Wrapping<$t> }
241241

242+
#[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")]
243+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
244+
impl const AddAssign<$t> for Wrapping<$t> {
245+
#[inline]
246+
fn add_assign(&mut self, other: $t) {
247+
*self = *self + Wrapping(other);
248+
}
249+
}
250+
forward_ref_op_assign! { impl const AddAssign, add_assign for Wrapping<$t>, $t }
251+
242252
#[stable(feature = "rust1", since = "1.0.0")]
243253
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
244254
impl const Sub for Wrapping<$t> {
@@ -262,6 +272,16 @@ macro_rules! wrapping_impl {
262272
}
263273
forward_ref_op_assign! { impl const SubAssign, sub_assign for Wrapping<$t>, Wrapping<$t> }
264274

275+
#[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")]
276+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
277+
impl const SubAssign<$t> for Wrapping<$t> {
278+
#[inline]
279+
fn sub_assign(&mut self, other: $t) {
280+
*self = *self - Wrapping(other);
281+
}
282+
}
283+
forward_ref_op_assign! { impl const SubAssign, sub_assign for Wrapping<$t>, $t }
284+
265285
#[stable(feature = "rust1", since = "1.0.0")]
266286
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
267287
impl const Mul for Wrapping<$t> {
@@ -285,6 +305,16 @@ macro_rules! wrapping_impl {
285305
}
286306
forward_ref_op_assign! { impl const MulAssign, mul_assign for Wrapping<$t>, Wrapping<$t> }
287307

308+
#[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")]
309+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
310+
impl const MulAssign<$t> for Wrapping<$t> {
311+
#[inline]
312+
fn mul_assign(&mut self, other: $t) {
313+
*self = *self * Wrapping(other);
314+
}
315+
}
316+
forward_ref_op_assign! { impl const MulAssign, mul_assign for Wrapping<$t>, $t }
317+
288318
#[stable(feature = "wrapping_div", since = "1.3.0")]
289319
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
290320
impl const Div for Wrapping<$t> {
@@ -308,6 +338,16 @@ macro_rules! wrapping_impl {
308338
}
309339
forward_ref_op_assign! { impl const DivAssign, div_assign for Wrapping<$t>, Wrapping<$t> }
310340

341+
#[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")]
342+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
343+
impl const DivAssign<$t> for Wrapping<$t> {
344+
#[inline]
345+
fn div_assign(&mut self, other: $t) {
346+
*self = *self / Wrapping(other);
347+
}
348+
}
349+
forward_ref_op_assign! { impl const DivAssign, div_assign for Wrapping<$t>, $t }
350+
311351
#[stable(feature = "wrapping_impls", since = "1.7.0")]
312352
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
313353
impl const Rem for Wrapping<$t> {
@@ -331,6 +371,16 @@ macro_rules! wrapping_impl {
331371
}
332372
forward_ref_op_assign! { impl const RemAssign, rem_assign for Wrapping<$t>, Wrapping<$t> }
333373

374+
#[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")]
375+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
376+
impl const RemAssign<$t> for Wrapping<$t> {
377+
#[inline]
378+
fn rem_assign(&mut self, other: $t) {
379+
*self = *self % Wrapping(other);
380+
}
381+
}
382+
forward_ref_op_assign! { impl const RemAssign, rem_assign for Wrapping<$t>, $t }
383+
334384
#[stable(feature = "rust1", since = "1.0.0")]
335385
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
336386
impl const Not for Wrapping<$t> {
@@ -367,6 +417,16 @@ macro_rules! wrapping_impl {
367417
}
368418
forward_ref_op_assign! { impl const BitXorAssign, bitxor_assign for Wrapping<$t>, Wrapping<$t> }
369419

420+
#[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")]
421+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
422+
impl const BitXorAssign<$t> for Wrapping<$t> {
423+
#[inline]
424+
fn bitxor_assign(&mut self, other: $t) {
425+
*self = *self ^ Wrapping(other);
426+
}
427+
}
428+
forward_ref_op_assign! { impl const BitXorAssign, bitxor_assign for Wrapping<$t>, $t }
429+
370430
#[stable(feature = "rust1", since = "1.0.0")]
371431
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
372432
impl const BitOr for Wrapping<$t> {
@@ -390,6 +450,16 @@ macro_rules! wrapping_impl {
390450
}
391451
forward_ref_op_assign! { impl const BitOrAssign, bitor_assign for Wrapping<$t>, Wrapping<$t> }
392452

453+
#[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")]
454+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
455+
impl const BitOrAssign<$t> for Wrapping<$t> {
456+
#[inline]
457+
fn bitor_assign(&mut self, other: $t) {
458+
*self = *self | Wrapping(other);
459+
}
460+
}
461+
forward_ref_op_assign! { impl const BitOrAssign, bitor_assign for Wrapping<$t>, $t }
462+
393463
#[stable(feature = "rust1", since = "1.0.0")]
394464
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
395465
impl const BitAnd for Wrapping<$t> {
@@ -413,6 +483,16 @@ macro_rules! wrapping_impl {
413483
}
414484
forward_ref_op_assign! { impl const BitAndAssign, bitand_assign for Wrapping<$t>, Wrapping<$t> }
415485

486+
#[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")]
487+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
488+
impl const BitAndAssign<$t> for Wrapping<$t> {
489+
#[inline]
490+
fn bitand_assign(&mut self, other: $t) {
491+
*self = *self & Wrapping(other);
492+
}
493+
}
494+
forward_ref_op_assign! { impl const BitAndAssign, bitand_assign for Wrapping<$t>, $t }
495+
416496
#[stable(feature = "wrapping_neg", since = "1.10.0")]
417497
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
418498
impl const Neg for Wrapping<$t> {

0 commit comments

Comments
 (0)