Also tidied up a few other nearby `#[must_use]`s.
///
/// assert!(abs_difference <= f32::EPSILON);
/// ```
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[stable(feature = "f32_deg_rad_conversions", since = "1.7.0")]
#[inline]
pub fn to_degrees(self) -> f32 {
///
/// assert!(abs_difference <= f32::EPSILON);
/// ```
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[stable(feature = "f32_deg_rad_conversions", since = "1.7.0")]
#[inline]
pub fn to_radians(self) -> f32 {
/// * Not be `NaN`
/// * Not be infinite
/// * Be representable in the return type `Int`, after truncating off its fractional part
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[stable(feature = "float_approx_unchecked_to", since = "1.44.0")]
#[inline]
pub unsafe fn to_int_unchecked<Int>(self) -> Int
/// assert_eq!((12.5f32).to_bits(), 0x41480000);
///
/// ```
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[stable(feature = "float_bits_conv", since = "1.20.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
/// let bytes = 12.5f32.to_be_bytes();
/// assert_eq!(bytes, [0x41, 0x48, 0x00, 0x00]);
/// ```
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
/// let bytes = 12.5f32.to_le_bytes();
/// assert_eq!(bytes, [0x00, 0x00, 0x48, 0x41]);
/// ```
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
/// }
/// );
/// ```
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
///
/// assert!(abs_difference < 1e-10);
/// ```
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn to_degrees(self) -> f64 {
///
/// assert!(abs_difference < 1e-10);
/// ```
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn to_radians(self) -> f64 {
/// * Not be `NaN`
/// * Not be infinite
/// * Be representable in the return type `Int`, after truncating off its fractional part
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[stable(feature = "float_approx_unchecked_to", since = "1.44.0")]
#[inline]
pub unsafe fn to_int_unchecked<Int>(self) -> Int
/// assert_eq!((12.5f64).to_bits(), 0x4029000000000000);
///
/// ```
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[stable(feature = "float_bits_conv", since = "1.20.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
/// let bytes = 12.5f64.to_be_bytes();
/// assert_eq!(bytes, [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
/// ```
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
/// let bytes = 12.5f64.to_le_bytes();
/// assert_eq!(bytes, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]);
/// ```
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
/// }
/// );
/// ```
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
#[rustc_const_unstable(feature = "const_float_bits_conv", issue = "72447")]
#[inline]
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
#[doc(alias = "popcount")]
#[doc(alias = "popcnt")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn count_ones(self) -> u32 { (self as $UnsignedT).count_ones() }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn count_zeros(self) -> u32 {
(!self).count_ones()
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn leading_zeros(self) -> u32 {
(self as $UnsignedT).leading_zeros()
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn trailing_zeros(self) -> u32 {
(self as $UnsignedT).trailing_zeros()
/// ```
#[stable(feature = "leading_trailing_ones", since = "1.46.0")]
#[rustc_const_stable(feature = "leading_trailing_ones", since = "1.46.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn leading_ones(self) -> u32 {
(self as $UnsignedT).leading_ones()
/// ```
#[stable(feature = "leading_trailing_ones", since = "1.46.0")]
#[rustc_const_stable(feature = "leading_trailing_ones", since = "1.46.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn trailing_ones(self) -> u32 {
(self as $UnsignedT).trailing_ones()
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn swap_bytes(self) -> Self {
(self as $UnsignedT).swap_bytes() as Self
/// ```
#[stable(feature = "reverse_bits", since = "1.37.0")]
#[rustc_const_stable(feature = "const_int_methods", since = "1.37.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
- #[must_use]
pub const fn reverse_bits(self) -> Self {
(self as $UnsignedT).reverse_bits() as Self
}
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_int_conversions", since = "1.32.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn to_be(self) -> Self { // or not to be?
#[cfg(target_endian = "big")]
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_int_conversions", since = "1.32.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn to_le(self) -> Self {
#[cfg(target_endian = "little")]
/// ```
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn checked_neg(self) -> Option<Self> {
let (a, b) = self.overflowing_neg();
/// ```
#[stable(feature = "no_panic_abs", since = "1.13.0")]
#[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn checked_abs(self) -> Option<Self> {
if self.is_negative() {
#[stable(feature = "saturating_neg", since = "1.45.0")]
#[rustc_const_stable(feature = "const_saturating_int_methods", since = "1.47.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn saturating_neg(self) -> Self {
intrinsics::saturating_sub(0, self)
#[stable(feature = "saturating_neg", since = "1.45.0")]
#[rustc_const_stable(feature = "const_saturating_int_methods", since = "1.47.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn saturating_abs(self) -> Self {
if self.is_negative() {
/// ```
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn wrapping_neg(self) -> Self {
(0 as $SelfT).wrapping_sub(self)
/// ```
#[stable(feature = "no_panic_abs", since = "1.13.0")]
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[allow(unused_attributes)]
#[inline]
pub const fn wrapping_abs(self) -> Self {
/// ```
#[stable(feature = "unsigned_abs", since = "1.51.0")]
#[rustc_const_stable(feature = "unsigned_abs", since = "1.51.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn unsigned_abs(self) -> $UnsignedT {
self.wrapping_abs() as $UnsignedT
#[inline]
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[allow(unused_attributes)]
pub const fn overflowing_neg(self) -> (Self, bool) {
if unlikely!(self == Self::MIN) {
/// ```
#[stable(feature = "no_panic_abs", since = "1.13.0")]
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn overflowing_abs(self) -> (Self, bool) {
(self.wrapping_abs(), self == Self::MIN)
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[must_use = "this returns the result of the operation, \
- without modifying the original"]
+ without modifying the original"]
#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[must_use = "this returns the result of the operation, \
- without modifying the original"]
+ without modifying the original"]
#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[must_use = "this returns the result of the operation, \
- without modifying the original"]
+ without modifying the original"]
#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[must_use = "this returns the result of the operation, \
- without modifying the original"]
+ without modifying the original"]
#[inline]
pub const fn checked_log(self, base: Self) -> Option<u32> {
if self <= 0 || base <= 1 {
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[must_use = "this returns the result of the operation, \
- without modifying the original"]
+ without modifying the original"]
#[inline]
pub const fn checked_log2(self) -> Option<u32> {
if self <= 0 {
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[must_use = "this returns the result of the operation, \
- without modifying the original"]
+ without modifying the original"]
#[inline]
pub const fn checked_log10(self) -> Option<u32> {
int_log10::$ActualT(self as $ActualT)
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
#[allow(unused_attributes)]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
#[rustc_inherit_overflow_checks]
pub const fn abs(self) -> Self {
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.abs_diff(", stringify!($SelfT), "::MAX), ", stringify!($UnsignedT), "::MAX);")]
/// ```
#[unstable(feature = "int_abs_diff", issue = "89492")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn abs_diff(self, other: Self) -> $UnsignedT {
if self < other {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_int_sign", since = "1.47.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn signum(self) -> Self {
match self {
/// ```
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] {
self.to_be().to_ne_bytes()
/// ```
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] {
self.to_le().to_ne_bytes()
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
// SAFETY: const sound because integers are plain old datatypes so we can always
// transmute them to arrays of bytes
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
// SAFETY: integers are plain old datatypes so we can always transmute them to
/// ```
#[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
#[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn leading_zeros(self) -> u32 {
// SAFETY: since `self` can not be zero it is safe to call ctlz_nonzero
/// ```
#[stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
#[rustc_const_stable(feature = "nonzero_leading_trailing_zeros", since = "1.53.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn trailing_zeros(self) -> u32 {
// SAFETY: since `self` can not be zero it is safe to call cttz_nonzero
/// # }
/// ```
#[unstable(feature = "nonzero_ops", issue = "84186")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn checked_add(self, other: $Int) -> Option<$Ty> {
if let Some(result) = self.get().checked_add(other) {
/// # }
/// ```
#[unstable(feature = "nonzero_ops", issue = "84186")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn saturating_add(self, other: $Int) -> $Ty {
// SAFETY: $Int::saturating_add returns $Int::MAX on overflow
/// # }
/// ```
#[unstable(feature = "nonzero_ops", issue = "84186")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const unsafe fn unchecked_add(self, other: $Int) -> $Ty {
// SAFETY: The caller ensures there is no overflow.
/// # }
/// ```
#[unstable(feature = "nonzero_ops", issue = "84186")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn checked_next_power_of_two(self) -> Option<$Ty> {
if let Some(nz) = self.get().checked_next_power_of_two() {
/// # }
/// ```
#[unstable(feature = "nonzero_ops", issue = "84186")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn abs(self) -> $Ty {
// SAFETY: This cannot overflow to zero.
/// # }
/// ```
#[unstable(feature = "nonzero_ops", issue = "84186")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn checked_abs(self) -> Option<$Ty> {
if let Some(nz) = self.get().checked_abs() {
/// # }
/// ```
#[unstable(feature = "nonzero_ops", issue = "84186")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn overflowing_abs(self) -> ($Ty, bool) {
let (nz, flag) = self.get().overflowing_abs();
/// # }
/// ```
#[unstable(feature = "nonzero_ops", issue = "84186")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn saturating_abs(self) -> $Ty {
// SAFETY: absolute value of nonzero cannot yield zero values.
/// # }
/// ```
#[unstable(feature = "nonzero_ops", issue = "84186")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn wrapping_abs(self) -> $Ty {
// SAFETY: absolute value of nonzero cannot yield zero values.
/// # }
/// ```
#[unstable(feature = "nonzero_ops", issue = "84186")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn unsigned_abs(self) -> $Uty {
// SAFETY: absolute value of nonzero cannot yield zero values.
/// # }
/// ```
#[unstable(feature = "nonzero_ops", issue = "84186")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn checked_mul(self, other: $Ty) -> Option<$Ty> {
if let Some(result) = self.get().checked_mul(other.get()) {
/// # }
/// ```
#[unstable(feature = "nonzero_ops", issue = "84186")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn saturating_mul(self, other: $Ty) -> $Ty {
// SAFETY: saturating_mul returns u*::MAX on overflow
/// # }
/// ```
#[unstable(feature = "nonzero_ops", issue = "84186")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const unsafe fn unchecked_mul(self, other: $Ty) -> $Ty {
// SAFETY: The caller ensures there is no overflow.
/// # }
/// ```
#[unstable(feature = "nonzero_ops", issue = "84186")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn checked_pow(self, other: u32) -> Option<$Ty> {
if let Some(result) = self.get().checked_pow(other) {
/// # }
/// ```
#[unstable(feature = "nonzero_ops", issue = "84186")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn saturating_pow(self, other: u32) -> $Ty {
// SAFETY: saturating_pow returns u*::MAX on overflow
#[inline]
#[doc(alias = "popcount")]
#[doc(alias = "popcnt")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "saturating_int_impl", issue = "87920")]
pub const fn count_ones(self) -> u32 {
self.0.count_ones()
#[doc = concat!("assert_eq!(Saturating(!0", stringify!($t), ").count_zeros(), 0);")]
/// ```
#[inline]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "saturating_int_impl", issue = "87920")]
pub const fn count_zeros(self) -> u32 {
self.0.count_zeros()
/// assert_eq!(n.trailing_zeros(), 3);
/// ```
#[inline]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "saturating_int_impl", issue = "87920")]
pub const fn trailing_zeros(self) -> u32 {
self.0.trailing_zeros()
/// assert_eq!(n.rotate_left(32), m);
/// ```
#[inline]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "saturating_int_impl", issue = "87920")]
pub const fn rotate_left(self, n: u32) -> Self {
Saturating(self.0.rotate_left(n))
/// assert_eq!(n.rotate_right(4), m);
/// ```
#[inline]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "saturating_int_impl", issue = "87920")]
pub const fn rotate_right(self, n: u32) -> Self {
Saturating(self.0.rotate_right(n))
/// assert_eq!(m, Saturating(21760));
/// ```
#[inline]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "saturating_int_impl", issue = "87920")]
pub const fn swap_bytes(self) -> Self {
Saturating(self.0.swap_bytes())
/// assert_eq!(m.0 as u16, 0b10101010_00000000);
/// assert_eq!(m, Saturating(-22016));
/// ```
+ #[inline]
#[unstable(feature = "saturating_int_impl", issue = "87920")]
#[rustc_const_stable(feature = "const_reverse_bits", since = "1.37.0")]
- #[inline]
- #[must_use]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
pub const fn reverse_bits(self) -> Self {
Saturating(self.0.reverse_bits())
}
/// ```
#[inline]
#[unstable(feature = "saturating_int_impl", issue = "87920")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
pub const fn to_be(self) -> Self {
Saturating(self.0.to_be())
}
/// ```
#[inline]
#[unstable(feature = "saturating_int_impl", issue = "87920")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
pub const fn to_le(self) -> Self {
Saturating(self.0.to_le())
}
/// ```
#[inline]
#[unstable(feature = "saturating_int_impl", issue = "87920")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
pub fn pow(self, exp: u32) -> Self {
Saturating(self.0.saturating_pow(exp))
}
/// ```
#[inline]
#[unstable(feature = "saturating_int_impl", issue = "87920")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
pub const fn leading_zeros(self) -> u32 {
self.0.leading_zeros()
}
/// ```
#[inline]
#[unstable(feature = "saturating_int_impl", issue = "87920")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
pub fn abs(self) -> Saturating<$t> {
Saturating(self.0.saturating_abs())
}
/// ```
#[inline]
#[unstable(feature = "saturating_int_impl", issue = "87920")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
pub fn signum(self) -> Saturating<$t> {
Saturating(self.0.signum())
}
/// ```
#[inline]
#[unstable(feature = "saturating_int_impl", issue = "87920")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
pub const fn leading_zeros(self) -> u32 {
self.0.leading_zeros()
}
#[rustc_const_stable(feature = "const_math", since = "1.32.0")]
#[doc(alias = "popcount")]
#[doc(alias = "popcnt")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn count_ones(self) -> u32 {
intrinsics::ctpop(self as $ActualT) as u32
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_math", since = "1.32.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn count_zeros(self) -> u32 {
(!self).count_ones()
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_math", since = "1.32.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn leading_zeros(self) -> u32 {
intrinsics::ctlz(self as $ActualT) as u32
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_math", since = "1.32.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn trailing_zeros(self) -> u32 {
intrinsics::cttz(self) as u32
/// ```
#[stable(feature = "leading_trailing_ones", since = "1.46.0")]
#[rustc_const_stable(feature = "leading_trailing_ones", since = "1.46.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn leading_ones(self) -> u32 {
(!self).leading_zeros()
/// ```
#[stable(feature = "leading_trailing_ones", since = "1.46.0")]
#[rustc_const_stable(feature = "leading_trailing_ones", since = "1.46.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn trailing_ones(self) -> u32 {
(!self).trailing_zeros()
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_math", since = "1.32.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn swap_bytes(self) -> Self {
intrinsics::bswap(self as $ActualT) as Self
/// ```
#[stable(feature = "reverse_bits", since = "1.37.0")]
#[rustc_const_stable(feature = "const_math", since = "1.37.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
- #[must_use]
pub const fn reverse_bits(self) -> Self {
intrinsics::bitreverse(self as $ActualT) as Self
}
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_math", since = "1.32.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn to_be(self) -> Self { // or not to be?
#[cfg(target_endian = "big")]
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_math", since = "1.32.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn to_le(self) -> Self {
#[cfg(target_endian = "little")]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[must_use = "this returns the result of the operation, \
- without modifying the original"]
+ without modifying the original"]
#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[must_use = "this returns the result of the operation, \
- without modifying the original"]
+ without modifying the original"]
#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[must_use = "this returns the result of the operation, \
- without modifying the original"]
+ without modifying the original"]
#[inline]
#[track_caller]
#[rustc_inherit_overflow_checks]
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[must_use = "this returns the result of the operation, \
- without modifying the original"]
+ without modifying the original"]
#[inline]
pub const fn checked_log(self, base: Self) -> Option<u32> {
if self <= 0 || base <= 1 {
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[must_use = "this returns the result of the operation, \
- without modifying the original"]
+ without modifying the original"]
#[inline]
pub const fn checked_log2(self) -> Option<u32> {
if self <= 0 {
/// ```
#[unstable(feature = "int_log", issue = "70887")]
#[must_use = "this returns the result of the operation, \
- without modifying the original"]
+ without modifying the original"]
#[inline]
pub const fn checked_log10(self) -> Option<u32> {
int_log10::$ActualT(self as $ActualT)
/// ```
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn checked_neg(self) -> Option<Self> {
let (a, b) = self.overflowing_neg();
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")]
#[must_use = "this returns the result of the operation, \
- without modifying the original"]
+ without modifying the original"]
#[inline(always)]
pub const fn wrapping_mul(self, rhs: Self) -> Self {
intrinsics::wrapping_mul(self, rhs)
/// ```
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
pub const fn wrapping_neg(self) -> Self {
(0 as $SelfT).wrapping_sub(self)
#[doc = concat!("assert_eq!(100", stringify!($SelfT), ".abs_diff(110), 10", stringify!($SelfT), ");")]
/// ```
#[unstable(feature = "int_abs_diff", issue = "89492")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn abs_diff(self, other: Self) -> Self {
if mem::size_of::<Self>() == 1 {
#[inline(always)]
#[stable(feature = "wrapping", since = "1.7.0")]
#[rustc_const_stable(feature = "const_wrapping_math", since = "1.32.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
pub const fn overflowing_neg(self) -> (Self, bool) {
((!self).wrapping_add(1), self != 0)
}
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")]
#[must_use = "this returns the result of the operation, \
- without modifying the original"]
+ without modifying the original"]
#[inline]
#[rustc_inherit_overflow_checks]
pub const fn pow(self, mut exp: u32) -> Self {
#[doc = concat!("assert_eq!(7_", stringify!($SelfT), ".unstable_div_floor(4), 1);")]
/// ```
#[unstable(feature = "int_roundings", issue = "88581")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline(always)]
#[rustc_inherit_overflow_checks]
pub const fn unstable_div_floor(self, rhs: Self) -> Self {
#[doc = concat!("assert_eq!(7_", stringify!($SelfT), ".unstable_div_ceil(4), 2);")]
/// ```
#[unstable(feature = "int_roundings", issue = "88581")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
#[rustc_inherit_overflow_checks]
pub const fn unstable_div_ceil(self, rhs: Self) -> Self {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
#[rustc_inherit_overflow_checks]
pub const fn next_power_of_two(self) -> Self {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
pub const fn checked_next_power_of_two(self) -> Option<Self> {
self.one_less_than_next_power_of_two().checked_add(1)
}
#[unstable(feature = "wrapping_next_power_of_two", issue = "32463",
reason = "needs decision on wrapping behaviour")]
#[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
pub const fn wrapping_next_power_of_two(self) -> Self {
self.one_less_than_next_power_of_two().wrapping_add(1)
}
/// ```
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] {
self.to_be().to_ne_bytes()
/// ```
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
pub const fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] {
self.to_le().to_ne_bytes()
/// ```
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
#[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
// SAFETY: const sound because integers are plain old datatypes so we can always
// transmute them to arrays of bytes
#[inline]
#[inline]
#[doc(alias = "popcount")]
#[doc(alias = "popcnt")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn count_ones(self) -> u32 {
self.0.count_ones()
#[doc = concat!("assert_eq!(Wrapping(!0", stringify!($t), ").count_zeros(), 0);")]
/// ```
#[inline]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn count_zeros(self) -> u32 {
self.0.count_zeros()
/// assert_eq!(n.trailing_zeros(), 3);
/// ```
#[inline]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn trailing_zeros(self) -> u32 {
self.0.trailing_zeros()
/// assert_eq!(n.rotate_left(32), m);
/// ```
#[inline]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn rotate_left(self, n: u32) -> Self {
Wrapping(self.0.rotate_left(n))
/// assert_eq!(n.rotate_right(4), m);
/// ```
#[inline]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn rotate_right(self, n: u32) -> Self {
Wrapping(self.0.rotate_right(n))
/// assert_eq!(m, Wrapping(21760));
/// ```
#[inline]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn swap_bytes(self) -> Self {
Wrapping(self.0.swap_bytes())
/// ```
#[stable(feature = "reverse_bits", since = "1.37.0")]
#[rustc_const_stable(feature = "const_reverse_bits", since = "1.37.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
- #[must_use]
pub const fn reverse_bits(self) -> Self {
Wrapping(self.0.reverse_bits())
}
/// }
/// ```
#[inline]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn to_be(self) -> Self {
Wrapping(self.0.to_be())
/// }
/// ```
#[inline]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn to_le(self) -> Self {
Wrapping(self.0.to_le())
/// assert_eq!(Wrapping(3i8).pow(6), Wrapping(-39));
/// ```
#[inline]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub fn pow(self, exp: u32) -> Self {
Wrapping(self.0.wrapping_pow(exp))
/// assert_eq!(n.leading_zeros(), 3);
/// ```
#[inline]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn leading_zeros(self) -> u32 {
self.0.leading_zeros()
/// assert_eq!(Wrapping(-128i8).abs().0 as u8, 128u8);
/// ```
#[inline]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub fn abs(self) -> Wrapping<$t> {
Wrapping(self.0.wrapping_abs())
#[doc = concat!("assert_eq!(Wrapping(-10", stringify!($t), ").signum(), Wrapping(-1));")]
/// ```
#[inline]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub fn signum(self) -> Wrapping<$t> {
Wrapping(self.0.signum())
/// assert_eq!(n.leading_zeros(), 2);
/// ```
#[inline]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub const fn leading_zeros(self) -> u32 {
self.0.leading_zeros()
#[doc = concat!("assert_eq!(Wrapping(200_u8).next_power_of_two(), Wrapping(0));")]
/// ```
#[inline]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[unstable(feature = "wrapping_next_power_of_two", issue = "32463",
reason = "needs decision on wrapping behaviour")]
pub fn next_power_of_two(self) -> Self {
/// assert_eq!(Duration::new(1, 0).checked_add(Duration::new(u64::MAX, 0)), None);
/// ```
#[stable(feature = "duration_checked_ops", since = "1.16.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
pub const fn checked_add(self, rhs: Duration) -> Option<Duration> {
/// assert_eq!(Duration::new(1, 0).saturating_add(Duration::new(u64::MAX, 0)), Duration::MAX);
/// ```
#[stable(feature = "duration_saturating_ops", since = "1.53.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
pub const fn saturating_add(self, rhs: Duration) -> Duration {
/// assert_eq!(Duration::new(0, 0).checked_sub(Duration::new(0, 1)), None);
/// ```
#[stable(feature = "duration_checked_ops", since = "1.16.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
pub const fn checked_sub(self, rhs: Duration) -> Option<Duration> {
/// assert_eq!(Duration::new(0, 0).saturating_sub(Duration::new(0, 1)), Duration::ZERO);
/// ```
#[stable(feature = "duration_saturating_ops", since = "1.53.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
pub const fn saturating_sub(self, rhs: Duration) -> Duration {
/// assert_eq!(Duration::new(u64::MAX - 1, 0).checked_mul(2), None);
/// ```
#[stable(feature = "duration_checked_ops", since = "1.16.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
pub const fn checked_mul(self, rhs: u32) -> Option<Duration> {
/// assert_eq!(Duration::new(u64::MAX - 1, 0).saturating_mul(2), Duration::MAX);
/// ```
#[stable(feature = "duration_saturating_ops", since = "1.53.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
pub const fn saturating_mul(self, rhs: u32) -> Duration {
/// assert_eq!(Duration::new(2, 0).checked_div(0), None);
/// ```
#[stable(feature = "duration_checked_ops", since = "1.16.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
pub const fn checked_div(self, rhs: u32) -> Option<Duration> {
/// assert_eq!(dur.mul_f64(3.14e5), Duration::new(847_800, 0));
/// ```
#[stable(feature = "duration_float", since = "1.38.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
pub const fn mul_f64(self, rhs: f64) -> Duration {
/// assert_eq!(dur.mul_f32(3.14e5), Duration::new(847799, 969_120_256));
/// ```
#[stable(feature = "duration_float", since = "1.38.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
pub const fn mul_f32(self, rhs: f32) -> Duration {
/// assert_eq!(dur.div_f64(3.14e5), Duration::new(0, 8_598));
/// ```
#[stable(feature = "duration_float", since = "1.38.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
pub const fn div_f64(self, rhs: f64) -> Duration {
/// assert_eq!(dur.div_f32(3.14e5), Duration::new(0, 8_598));
/// ```
#[stable(feature = "duration_float", since = "1.38.0")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
pub const fn div_f32(self, rhs: f32) -> Duration {
/// assert_eq!(dur1.div_duration_f64(dur2), 0.5);
/// ```
#[unstable(feature = "div_duration", issue = "63139")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
pub const fn div_duration_f64(self, rhs: Duration) -> f64 {
/// assert_eq!(dur1.div_duration_f32(dur2), 0.5);
/// ```
#[unstable(feature = "div_duration", issue = "63139")]
+ #[must_use = "this returns the result of the operation, \
+ without modifying the original"]
#[inline]
#[rustc_const_unstable(feature = "duration_consts_2", issue = "72440")]
pub const fn div_duration_f32(self, rhs: Duration) -> f32 {