Skip to content

Commit

Permalink
Rollup merge of rust-lang#93353 - kellerkindt:saturating_int_assign_i…
Browse files Browse the repository at this point in the history
…mpl, r=joshtriplett

Unimpl {Add,Sub,Mul,Div,Rem,BitXor,BitOr,BitAnd}<$t> for Saturating<$t>

Tracking issue rust-lang#92354

Analog to 9648b31 rust-lang#93208 reduce `saturating_int_assign_impl` (rust-lang#93208) to:

```rust
let mut value = Saturating(2u8);
value += 3u8;
value -= 1u8;
value *= 2u8;
value /= 2u8;
value %= 2u8;
value ^= 255u8;
value |= 123u8;
value &= 2u8;
```

See rust-lang#93208 (comment)
  • Loading branch information
matthiaskrgr authored Jan 28, 2022
2 parents 4f2e2ce + a6c0a3d commit 25cd639
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 25cd639

Please sign in to comment.