Skip to content

Commit

Permalink
Unimpl {Add,Sub,Mul,Div,Rem,BitXor,BitOr,BitAnd}<$t> for Saturating<$t>
Browse files Browse the repository at this point in the history
  • Loading branch information
kellerkindt committed Jan 26, 2022
1 parent a7f3757 commit a6c0a3d
Showing 1 changed file with 8 additions and 122 deletions.
130 changes: 8 additions & 122 deletions library/core/src/num/saturating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,6 @@ macro_rules! saturating_impl {
forward_ref_binop! { impl Add, add for Saturating<$t>, Saturating<$t>,
#[unstable(feature = "saturating_int_impl", issue = "87920")] }

#[unstable(feature = "saturating_int_assign_impl", issue = "92354")]
impl Add<$t> for Saturating<$t> {
type Output = Saturating<$t>;

#[inline]
fn add(self, other: $t) -> Saturating<$t> {
Saturating(self.0.saturating_add(other))
}
}
forward_ref_binop! { impl Add, add for Saturating<$t>, $t,
#[unstable(feature = "saturating_int_assign_impl", issue = "92354")] }

#[unstable(feature = "saturating_int_impl", issue = "87920")]
impl AddAssign for Saturating<$t> {
#[inline]
Expand All @@ -242,7 +230,7 @@ macro_rules! saturating_impl {
impl AddAssign<$t> for Saturating<$t> {
#[inline]
fn add_assign(&mut self, other: $t) {
*self = *self + other;
*self = *self + Saturating(other);
}
}
forward_ref_op_assign! { impl AddAssign, add_assign for Saturating<$t>, $t }
Expand All @@ -259,18 +247,6 @@ macro_rules! saturating_impl {
forward_ref_binop! { impl Sub, sub for Saturating<$t>, Saturating<$t>,
#[unstable(feature = "saturating_int_impl", issue = "87920")] }

#[unstable(feature = "saturating_int_assign_impl", issue = "92354")]
impl Sub<$t> for Saturating<$t> {
type Output = Saturating<$t>;

#[inline]
fn sub(self, other: $t) -> Saturating<$t> {
Saturating(self.0.saturating_sub(other))
}
}
forward_ref_binop! { impl Sub, sub for Saturating<$t>, $t,
#[unstable(feature = "saturating_int_assign_impl", issue = "92354")] }

#[unstable(feature = "saturating_int_impl", issue = "87920")]
impl SubAssign for Saturating<$t> {
#[inline]
Expand All @@ -284,7 +260,7 @@ macro_rules! saturating_impl {
impl SubAssign<$t> for Saturating<$t> {
#[inline]
fn sub_assign(&mut self, other: $t) {
*self = *self - other;
*self = *self - Saturating(other);
}
}
forward_ref_op_assign! { impl SubAssign, sub_assign for Saturating<$t>, $t }
Expand All @@ -301,18 +277,6 @@ macro_rules! saturating_impl {
forward_ref_binop! { impl Mul, mul for Saturating<$t>, Saturating<$t>,
#[unstable(feature = "saturating_int_impl", issue = "87920")] }

#[unstable(feature = "saturating_int_assign_impl", issue = "92354")]
impl Mul<$t> for Saturating<$t> {
type Output = Saturating<$t>;

#[inline]
fn mul(self, other: $t) -> Saturating<$t> {
Saturating(self.0.saturating_mul(other))
}
}
forward_ref_binop! { impl Mul, mul for Saturating<$t>, $t,
#[unstable(feature = "saturating_int_assign_impl", issue = "92354")] }

#[unstable(feature = "saturating_int_impl", issue = "87920")]
impl MulAssign for Saturating<$t> {
#[inline]
Expand All @@ -326,7 +290,7 @@ macro_rules! saturating_impl {
impl MulAssign<$t> for Saturating<$t> {
#[inline]
fn mul_assign(&mut self, other: $t) {
*self = *self * other;
*self = *self * Saturating(other);
}
}
forward_ref_op_assign! { impl MulAssign, mul_assign for Saturating<$t>, $t }
Expand Down Expand Up @@ -362,36 +326,6 @@ macro_rules! saturating_impl {
forward_ref_binop! { impl Div, div for Saturating<$t>, Saturating<$t>,
#[unstable(feature = "saturating_int_impl", issue = "87920")] }

/// # Examples
///
/// Basic usage:
///
/// ```
/// #![feature(saturating_int_impl, saturating_int_assign_impl)]
/// use std::num::Saturating;
///
#[doc = concat!("assert_eq!(Saturating(2", stringify!($t), "), Saturating(5", stringify!($t), ") / 2);")]
#[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MAX), Saturating(", stringify!($t), "::MAX) / 1);")]
#[doc = concat!("assert_eq!(Saturating(", stringify!($t), "::MIN), Saturating(", stringify!($t), "::MIN) / 1);")]
/// ```
///
/// ```should_panic
/// #![feature(saturating_int_impl, saturating_int_assign_impl)]
/// use std::num::Saturating;
///
#[doc = concat!("let _ = Saturating(0", stringify!($t), ") / 0;")]
/// ```
#[unstable(feature = "saturating_int_assign_impl", issue = "92354")]
impl Div<$t> for Saturating<$t> {
type Output = Saturating<$t>;

#[inline]
fn div(self, other: $t) -> Saturating<$t> {
Saturating(self.0.saturating_div(other))
}
}
forward_ref_binop! { impl Div, div for Saturating<$t>, $t,
#[unstable(feature = "saturating_int_assign_impl", issue = "92354")] }

#[unstable(feature = "saturating_int_impl", issue = "87920")]
impl DivAssign for Saturating<$t> {
Expand All @@ -406,7 +340,7 @@ macro_rules! saturating_impl {
impl DivAssign<$t> for Saturating<$t> {
#[inline]
fn div_assign(&mut self, other: $t) {
*self = *self / other;
*self = *self / Saturating(other);
}
}
forward_ref_op_assign! { impl DivAssign, div_assign for Saturating<$t>, $t }
Expand All @@ -423,18 +357,6 @@ macro_rules! saturating_impl {
forward_ref_binop! { impl Rem, rem for Saturating<$t>, Saturating<$t>,
#[unstable(feature = "saturating_int_impl", issue = "87920")] }

#[unstable(feature = "saturating_int_assign_impl", issue = "92354")]
impl Rem<$t> for Saturating<$t> {
type Output = Saturating<$t>;

#[inline]
fn rem(self, other: $t) -> Saturating<$t> {
Saturating(self.0.rem(other))
}
}
forward_ref_binop! { impl Rem, rem for Saturating<$t>, $t,
#[unstable(feature = "saturating_int_assign_impl", issue = "92354")] }

#[unstable(feature = "saturating_int_impl", issue = "87920")]
impl RemAssign for Saturating<$t> {
#[inline]
Expand All @@ -448,7 +370,7 @@ macro_rules! saturating_impl {
impl RemAssign<$t> for Saturating<$t> {
#[inline]
fn rem_assign(&mut self, other: $t) {
*self = *self % other;
*self = *self % Saturating(other);
}
}
forward_ref_op_assign! { impl RemAssign, rem_assign for Saturating<$t>, $t }
Expand Down Expand Up @@ -477,18 +399,6 @@ macro_rules! saturating_impl {
forward_ref_binop! { impl BitXor, bitxor for Saturating<$t>, Saturating<$t>,
#[unstable(feature = "saturating_int_impl", issue = "87920")] }

#[unstable(feature = "saturating_int_assign_impl", issue = "92354")]
impl BitXor<$t> for Saturating<$t> {
type Output = Saturating<$t>;

#[inline]
fn bitxor(self, other: $t) -> Saturating<$t> {
Saturating(self.0 ^ other)
}
}
forward_ref_binop! { impl BitXor, bitxor for Saturating<$t>, $t,
#[unstable(feature = "saturating_int_assign_impl", issue = "92354")] }

#[unstable(feature = "saturating_int_impl", issue = "87920")]
impl BitXorAssign for Saturating<$t> {
#[inline]
Expand All @@ -502,7 +412,7 @@ macro_rules! saturating_impl {
impl BitXorAssign<$t> for Saturating<$t> {
#[inline]
fn bitxor_assign(&mut self, other: $t) {
*self = *self ^ other;
*self = *self ^ Saturating(other);
}
}
forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Saturating<$t>, $t }
Expand All @@ -519,18 +429,6 @@ macro_rules! saturating_impl {
forward_ref_binop! { impl BitOr, bitor for Saturating<$t>, Saturating<$t>,
#[unstable(feature = "saturating_int_impl", issue = "87920")] }

#[unstable(feature = "saturating_int_assign_impl", issue = "92354")]
impl BitOr<$t> for Saturating<$t> {
type Output = Saturating<$t>;

#[inline]
fn bitor(self, other: $t) -> Saturating<$t> {
Saturating(self.0 | other)
}
}
forward_ref_binop! { impl BitOr, bitor for Saturating<$t>, $t,
#[unstable(feature = "saturating_int_assign_impl", issue = "92354")] }

#[unstable(feature = "saturating_int_impl", issue = "87920")]
impl BitOrAssign for Saturating<$t> {
#[inline]
Expand All @@ -544,7 +442,7 @@ macro_rules! saturating_impl {
impl BitOrAssign<$t> for Saturating<$t> {
#[inline]
fn bitor_assign(&mut self, other: $t) {
*self = *self | other;
*self = *self | Saturating(other);
}
}
forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Saturating<$t>, $t }
Expand All @@ -561,18 +459,6 @@ macro_rules! saturating_impl {
forward_ref_binop! { impl BitAnd, bitand for Saturating<$t>, Saturating<$t>,
#[unstable(feature = "saturating_int_impl", issue = "87920")] }

#[unstable(feature = "saturating_int_assign_impl", issue = "92354")]
impl BitAnd<$t> for Saturating<$t> {
type Output = Saturating<$t>;

#[inline]
fn bitand(self, other: $t) -> Saturating<$t> {
Saturating(self.0 & other)
}
}
forward_ref_binop! { impl BitAnd, bitand for Saturating<$t>, $t,
#[unstable(feature = "saturating_int_assign_impl", issue = "92354")] }

#[unstable(feature = "saturating_int_impl", issue = "87920")]
impl BitAndAssign for Saturating<$t> {
#[inline]
Expand All @@ -586,7 +472,7 @@ macro_rules! saturating_impl {
impl BitAndAssign<$t> for Saturating<$t> {
#[inline]
fn bitand_assign(&mut self, other: $t) {
*self = *self & other;
*self = *self & Saturating(other);
}
}
forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Saturating<$t>, $t }
Expand Down

0 comments on commit a6c0a3d

Please sign in to comment.