From 9648b313cc8896970a12f45b3bb5c0593c3d510f Mon Sep 17 00:00:00 2001 From: Michael Watzko Date: Sat, 22 Jan 2022 17:14:09 +0100 Subject: [PATCH 1/2] Impl {Add,Sub,Mul,Div,Rem,BitXor,BitOr,BitAnd}Assign<$t> for Wrapping<$t> Analog to 1c0dc1810d778bb6fea16aac02cafc5aa2e84b11 #92356 --- library/core/src/num/wrapping.rs | 80 ++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/library/core/src/num/wrapping.rs b/library/core/src/num/wrapping.rs index a0e42c51e4517..64cf7ac347a13 100644 --- a/library/core/src/num/wrapping.rs +++ b/library/core/src/num/wrapping.rs @@ -239,6 +239,16 @@ macro_rules! wrapping_impl { } forward_ref_op_assign! { impl const AddAssign, add_assign for Wrapping<$t>, Wrapping<$t> } + #[stable(feature = "wrapping_int_assign_impl", since = "1.61.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "90080")] + impl const AddAssign<$t> for Wrapping<$t> { + #[inline] + fn add_assign(&mut self, other: $t) { + *self = *self + Wrapping(other); + } + } + forward_ref_op_assign! { impl const AddAssign, add_assign for Wrapping<$t>, $t } + #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_ops", issue = "90080")] impl const Sub for Wrapping<$t> { @@ -262,6 +272,16 @@ macro_rules! wrapping_impl { } forward_ref_op_assign! { impl const SubAssign, sub_assign for Wrapping<$t>, Wrapping<$t> } + #[stable(feature = "wrapping_int_assign_impl", since = "1.61.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "90080")] + impl const SubAssign<$t> for Wrapping<$t> { + #[inline] + fn sub_assign(&mut self, other: $t) { + *self = *self - Wrapping(other); + } + } + forward_ref_op_assign! { impl const SubAssign, sub_assign for Wrapping<$t>, $t } + #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_ops", issue = "90080")] impl const Mul for Wrapping<$t> { @@ -285,6 +305,16 @@ macro_rules! wrapping_impl { } forward_ref_op_assign! { impl const MulAssign, mul_assign for Wrapping<$t>, Wrapping<$t> } + #[stable(feature = "wrapping_int_assign_impl", since = "1.61.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "90080")] + impl const MulAssign<$t> for Wrapping<$t> { + #[inline] + fn mul_assign(&mut self, other: $t) { + *self = *self * Wrapping(other); + } + } + forward_ref_op_assign! { impl const MulAssign, mul_assign for Wrapping<$t>, $t } + #[stable(feature = "wrapping_div", since = "1.3.0")] #[rustc_const_unstable(feature = "const_ops", issue = "90080")] impl const Div for Wrapping<$t> { @@ -308,6 +338,16 @@ macro_rules! wrapping_impl { } forward_ref_op_assign! { impl const DivAssign, div_assign for Wrapping<$t>, Wrapping<$t> } + #[stable(feature = "wrapping_int_assign_impl", since = "1.61.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "90080")] + impl const DivAssign<$t> for Wrapping<$t> { + #[inline] + fn div_assign(&mut self, other: $t) { + *self = *self / Wrapping(other); + } + } + forward_ref_op_assign! { impl const DivAssign, div_assign for Wrapping<$t>, $t } + #[stable(feature = "wrapping_impls", since = "1.7.0")] #[rustc_const_unstable(feature = "const_ops", issue = "90080")] impl const Rem for Wrapping<$t> { @@ -331,6 +371,16 @@ macro_rules! wrapping_impl { } forward_ref_op_assign! { impl const RemAssign, rem_assign for Wrapping<$t>, Wrapping<$t> } + #[stable(feature = "wrapping_int_assign_impl", since = "1.61.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "90080")] + impl const RemAssign<$t> for Wrapping<$t> { + #[inline] + fn rem_assign(&mut self, other: $t) { + *self = *self % Wrapping(other); + } + } + forward_ref_op_assign! { impl const RemAssign, rem_assign for Wrapping<$t>, $t } + #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_ops", issue = "90080")] impl const Not for Wrapping<$t> { @@ -367,6 +417,16 @@ macro_rules! wrapping_impl { } forward_ref_op_assign! { impl const BitXorAssign, bitxor_assign for Wrapping<$t>, Wrapping<$t> } + #[stable(feature = "wrapping_int_assign_impl", since = "1.61.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "90080")] + impl const BitXorAssign<$t> for Wrapping<$t> { + #[inline] + fn bitxor_assign(&mut self, other: $t) { + *self = *self ^ Wrapping(other); + } + } + forward_ref_op_assign! { impl const BitXorAssign, bitxor_assign for Wrapping<$t>, $t } + #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_ops", issue = "90080")] impl const BitOr for Wrapping<$t> { @@ -390,6 +450,16 @@ macro_rules! wrapping_impl { } forward_ref_op_assign! { impl const BitOrAssign, bitor_assign for Wrapping<$t>, Wrapping<$t> } + #[stable(feature = "wrapping_int_assign_impl", since = "1.61.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "90080")] + impl const BitOrAssign<$t> for Wrapping<$t> { + #[inline] + fn bitor_assign(&mut self, other: $t) { + *self = *self | Wrapping(other); + } + } + forward_ref_op_assign! { impl const BitOrAssign, bitor_assign for Wrapping<$t>, $t } + #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_ops", issue = "90080")] impl const BitAnd for Wrapping<$t> { @@ -413,6 +483,16 @@ macro_rules! wrapping_impl { } forward_ref_op_assign! { impl const BitAndAssign, bitand_assign for Wrapping<$t>, Wrapping<$t> } + #[stable(feature = "wrapping_int_assign_impl", since = "1.61.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "90080")] + impl const BitAndAssign<$t> for Wrapping<$t> { + #[inline] + fn bitand_assign(&mut self, other: $t) { + *self = *self & Wrapping(other); + } + } + forward_ref_op_assign! { impl const BitAndAssign, bitand_assign for Wrapping<$t>, $t } + #[stable(feature = "wrapping_neg", since = "1.10.0")] #[rustc_const_unstable(feature = "const_ops", issue = "90080")] impl const Neg for Wrapping<$t> { From 14ff58cd862e3dff8d87e445932d37116924aeb2 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Mon, 7 Feb 2022 11:45:12 +0100 Subject: [PATCH 2/2] Stabilize wrapping_int_assign_impl in 1.60.0. --- library/core/src/num/wrapping.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/library/core/src/num/wrapping.rs b/library/core/src/num/wrapping.rs index 64cf7ac347a13..5353d900e7662 100644 --- a/library/core/src/num/wrapping.rs +++ b/library/core/src/num/wrapping.rs @@ -239,7 +239,7 @@ macro_rules! wrapping_impl { } forward_ref_op_assign! { impl const AddAssign, add_assign for Wrapping<$t>, Wrapping<$t> } - #[stable(feature = "wrapping_int_assign_impl", since = "1.61.0")] + #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] #[rustc_const_unstable(feature = "const_ops", issue = "90080")] impl const AddAssign<$t> for Wrapping<$t> { #[inline] @@ -272,7 +272,7 @@ macro_rules! wrapping_impl { } forward_ref_op_assign! { impl const SubAssign, sub_assign for Wrapping<$t>, Wrapping<$t> } - #[stable(feature = "wrapping_int_assign_impl", since = "1.61.0")] + #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] #[rustc_const_unstable(feature = "const_ops", issue = "90080")] impl const SubAssign<$t> for Wrapping<$t> { #[inline] @@ -305,7 +305,7 @@ macro_rules! wrapping_impl { } forward_ref_op_assign! { impl const MulAssign, mul_assign for Wrapping<$t>, Wrapping<$t> } - #[stable(feature = "wrapping_int_assign_impl", since = "1.61.0")] + #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] #[rustc_const_unstable(feature = "const_ops", issue = "90080")] impl const MulAssign<$t> for Wrapping<$t> { #[inline] @@ -338,7 +338,7 @@ macro_rules! wrapping_impl { } forward_ref_op_assign! { impl const DivAssign, div_assign for Wrapping<$t>, Wrapping<$t> } - #[stable(feature = "wrapping_int_assign_impl", since = "1.61.0")] + #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] #[rustc_const_unstable(feature = "const_ops", issue = "90080")] impl const DivAssign<$t> for Wrapping<$t> { #[inline] @@ -371,7 +371,7 @@ macro_rules! wrapping_impl { } forward_ref_op_assign! { impl const RemAssign, rem_assign for Wrapping<$t>, Wrapping<$t> } - #[stable(feature = "wrapping_int_assign_impl", since = "1.61.0")] + #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] #[rustc_const_unstable(feature = "const_ops", issue = "90080")] impl const RemAssign<$t> for Wrapping<$t> { #[inline] @@ -417,7 +417,7 @@ macro_rules! wrapping_impl { } forward_ref_op_assign! { impl const BitXorAssign, bitxor_assign for Wrapping<$t>, Wrapping<$t> } - #[stable(feature = "wrapping_int_assign_impl", since = "1.61.0")] + #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] #[rustc_const_unstable(feature = "const_ops", issue = "90080")] impl const BitXorAssign<$t> for Wrapping<$t> { #[inline] @@ -450,7 +450,7 @@ macro_rules! wrapping_impl { } forward_ref_op_assign! { impl const BitOrAssign, bitor_assign for Wrapping<$t>, Wrapping<$t> } - #[stable(feature = "wrapping_int_assign_impl", since = "1.61.0")] + #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] #[rustc_const_unstable(feature = "const_ops", issue = "90080")] impl const BitOrAssign<$t> for Wrapping<$t> { #[inline] @@ -483,7 +483,7 @@ macro_rules! wrapping_impl { } forward_ref_op_assign! { impl const BitAndAssign, bitand_assign for Wrapping<$t>, Wrapping<$t> } - #[stable(feature = "wrapping_int_assign_impl", since = "1.61.0")] + #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] #[rustc_const_unstable(feature = "const_ops", issue = "90080")] impl const BitAndAssign<$t> for Wrapping<$t> { #[inline]