Skip to content

Implement operations for Wrapping<T> where Rhs = T #140567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions library/core/src/num/wrapping.rs
Original file line number Diff line number Diff line change
@@ -221,6 +221,18 @@ macro_rules! wrapping_impl {
forward_ref_binop! { impl Add, add for Wrapping<$t>, Wrapping<$t>,
#[stable(feature = "wrapping_ref", since = "1.14.0")] }


#[stable(feature = "wrapping_int_impl_int", since = "CURRENT_RUSTC_VERSION")]
impl Add<$t> for Wrapping<$t> {
type Output = Wrapping<$t>;

#[inline]
fn add(self, other: $t) -> Wrapping<$t> {
Wrapping(self.0.wrapping_add(other))
}
}
forward_ref_binop! { impl Add, add for Wrapping<$t>, $t }

#[stable(feature = "op_assign_traits", since = "1.8.0")]
impl AddAssign for Wrapping<$t> {
#[inline]
@@ -251,6 +263,17 @@ macro_rules! wrapping_impl {
forward_ref_binop! { impl Sub, sub for Wrapping<$t>, Wrapping<$t>,
#[stable(feature = "wrapping_ref", since = "1.14.0")] }

#[stable(feature = "wrapping_int_impl_int", since = "CURRENT_RUSTC_VERSION")]
impl Sub<$t> for Wrapping<$t> {
type Output = Wrapping<$t>;

#[inline]
fn sub(self, other: $t) -> Wrapping<$t> {
Wrapping(self.0.wrapping_sub(other))
}
}
forward_ref_binop! { impl Sub, sub for Wrapping<$t>, $t }

#[stable(feature = "op_assign_traits", since = "1.8.0")]
impl SubAssign for Wrapping<$t> {
#[inline]
@@ -281,6 +304,17 @@ macro_rules! wrapping_impl {
forward_ref_binop! { impl Mul, mul for Wrapping<$t>, Wrapping<$t>,
#[stable(feature = "wrapping_ref", since = "1.14.0")] }

#[stable(feature = "wrapping_int_impl_int", since = "CURRENT_RUSTC_VERSION")]
impl Mul<$t> for Wrapping<$t> {
type Output = Wrapping<$t>;

#[inline]
fn mul(self, other: $t) -> Wrapping<$t> {
Wrapping(self.0.wrapping_mul(other))
}
}
forward_ref_binop! { impl Mul, mul for Wrapping<$t>, $t }

#[stable(feature = "op_assign_traits", since = "1.8.0")]
impl MulAssign for Wrapping<$t> {
#[inline]
@@ -311,6 +345,17 @@ macro_rules! wrapping_impl {
forward_ref_binop! { impl Div, div for Wrapping<$t>, Wrapping<$t>,
#[stable(feature = "wrapping_ref", since = "1.14.0")] }

#[stable(feature = "wrapping_int_impl_int", since = "CURRENT_RUSTC_VERSION")]
impl Div<$t> for Wrapping<$t> {
type Output = Wrapping<$t>;

#[inline]
fn div(self, other: $t) -> Wrapping<$t> {
Wrapping(self.0.wrapping_div(other))
}
}
forward_ref_binop! { impl Div, div for Wrapping<$t>, $t }

#[stable(feature = "op_assign_traits", since = "1.8.0")]
impl DivAssign for Wrapping<$t> {
#[inline]
@@ -341,6 +386,17 @@ macro_rules! wrapping_impl {
forward_ref_binop! { impl Rem, rem for Wrapping<$t>, Wrapping<$t>,
#[stable(feature = "wrapping_ref", since = "1.14.0")] }

#[stable(feature = "wrapping_int_impl_int", since = "CURRENT_RUSTC_VERSION")]
impl Rem<$t> for Wrapping<$t> {
type Output = Wrapping<$t>;

#[inline]
fn rem(self, other: $t) -> Wrapping<$t> {
Wrapping(self.0.wrapping_rem(other))
}
}
forward_ref_binop! { impl Rem, rem for Wrapping<$t>, $t }

#[stable(feature = "op_assign_traits", since = "1.8.0")]
impl RemAssign for Wrapping<$t> {
#[inline]
@@ -383,6 +439,17 @@ macro_rules! wrapping_impl {
forward_ref_binop! { impl BitXor, bitxor for Wrapping<$t>, Wrapping<$t>,
#[stable(feature = "wrapping_ref", since = "1.14.0")] }

#[stable(feature = "wrapping_int_impl_int", since = "CURRENT_RUSTC_VERSION")]
impl BitXor<$t> for Wrapping<$t> {
type Output = Wrapping<$t>;

#[inline]
fn bitxor(self, other: $t) -> Wrapping<$t> {
Wrapping(self.0 ^ other)
}
}
forward_ref_binop! { impl BitXor, bitxor for Wrapping<$t>, $t }

#[stable(feature = "op_assign_traits", since = "1.8.0")]
impl BitXorAssign for Wrapping<$t> {
#[inline]
@@ -413,6 +480,17 @@ macro_rules! wrapping_impl {
forward_ref_binop! { impl BitOr, bitor for Wrapping<$t>, Wrapping<$t>,
#[stable(feature = "wrapping_ref", since = "1.14.0")] }

#[stable(feature = "wrapping_int_impl_int", since = "CURRENT_RUSTC_VERSION")]
impl BitOr<$t> for Wrapping<$t> {
type Output = Wrapping<$t>;

#[inline]
fn bitor(self, other: $t) -> Wrapping<$t> {
Wrapping(self.0 | other)
}
}
forward_ref_binop! { impl BitOr, bitor for Wrapping<$t>, $t }

#[stable(feature = "op_assign_traits", since = "1.8.0")]
impl BitOrAssign for Wrapping<$t> {
#[inline]
@@ -443,6 +521,17 @@ macro_rules! wrapping_impl {
forward_ref_binop! { impl BitAnd, bitand for Wrapping<$t>, Wrapping<$t>,
#[stable(feature = "wrapping_ref", since = "1.14.0")] }

#[stable(feature = "wrapping_int_impl_int", since = "CURRENT_RUSTC_VERSION")]
impl BitAnd<$t> for Wrapping<$t> {
type Output = Wrapping<$t>;

#[inline]
fn bitand(self, other: $t) -> Wrapping<$t> {
Wrapping(self.0 & other)
}
}
forward_ref_binop! { impl BitAnd, bitand for Wrapping<$t>, $t }

#[stable(feature = "op_assign_traits", since = "1.8.0")]
impl BitAndAssign for Wrapping<$t> {
#[inline]