Rollup merge of #89720 - jkugelman:must-use-math-operations, r=joshtriplett

Add #[must_use] to math and bit manipulation methods

Also tidied up a few other nearby `#[must_use]`s.

Parent issue: #89692
This commit is contained in:
Matthias Krüger 2021-10-10 18:22:25 +02:00 committed by GitHub
commit c8b5a7b0c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 255 additions and 19 deletions

View File

@ -643,6 +643,8 @@ impl 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_degrees(self) -> f32 {
@ -660,6 +662,8 @@ impl 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 {
@ -719,6 +723,8 @@ impl 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
@ -747,6 +753,8 @@ impl f32 {
/// 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]
@ -809,6 +817,8 @@ impl f32 {
/// 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]
@ -825,6 +835,8 @@ impl f32 {
/// 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]
@ -854,6 +866,8 @@ impl f32 {
/// }
/// );
/// ```
#[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]

View File

@ -658,6 +658,8 @@ impl 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_degrees(self) -> f64 {
@ -676,6 +678,8 @@ impl 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 {
@ -735,6 +739,8 @@ impl 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
@ -763,6 +769,8 @@ impl f64 {
/// 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]
@ -825,6 +833,8 @@ impl f64 {
/// 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]
@ -841,6 +851,8 @@ impl f64 {
/// 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]
@ -870,6 +882,8 @@ impl f64 {
/// }
/// );
/// ```
#[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]

View File

@ -81,6 +81,8 @@ macro_rules! int_impl {
#[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() }
@ -95,6 +97,8 @@ macro_rules! int_impl {
/// ```
#[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()
@ -113,6 +117,8 @@ macro_rules! int_impl {
/// ```
#[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()
@ -131,6 +137,8 @@ macro_rules! int_impl {
/// ```
#[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()
@ -149,6 +157,8 @@ macro_rules! int_impl {
/// ```
#[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()
@ -167,6 +177,8 @@ macro_rules! int_impl {
/// ```
#[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()
@ -236,6 +248,8 @@ macro_rules! int_impl {
/// ```
#[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
@ -257,8 +271,9 @@ macro_rules! int_impl {
/// ```
#[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
}
@ -344,6 +359,8 @@ macro_rules! int_impl {
/// ```
#[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")]
@ -375,6 +392,8 @@ macro_rules! int_impl {
/// ```
#[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")]
@ -689,6 +708,8 @@ macro_rules! int_impl {
/// ```
#[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();
@ -801,6 +822,8 @@ macro_rules! int_impl {
/// ```
#[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() {
@ -959,6 +982,8 @@ macro_rules! int_impl {
#[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)
@ -980,6 +1005,8 @@ macro_rules! int_impl {
#[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() {
@ -1308,6 +1335,8 @@ macro_rules! int_impl {
/// ```
#[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)
@ -1390,6 +1419,8 @@ macro_rules! int_impl {
/// ```
#[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 {
@ -1415,6 +1446,8 @@ macro_rules! int_impl {
/// ```
#[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
@ -1781,6 +1814,8 @@ macro_rules! int_impl {
#[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) {
@ -1855,6 +1890,8 @@ macro_rules! int_impl {
/// ```
#[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)
@ -2220,7 +2257,7 @@ macro_rules! int_impl {
/// ```
#[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]
@ -2253,7 +2290,7 @@ macro_rules! int_impl {
/// ```
#[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]
@ -2286,7 +2323,7 @@ macro_rules! int_impl {
/// ```
#[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]
@ -2321,7 +2358,7 @@ macro_rules! int_impl {
/// ```
#[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 {
@ -2357,7 +2394,7 @@ macro_rules! int_impl {
/// ```
#[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 {
@ -2381,7 +2418,7 @@ macro_rules! int_impl {
/// ```
#[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)
@ -2412,6 +2449,8 @@ macro_rules! int_impl {
#[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 {
@ -2443,6 +2482,8 @@ macro_rules! int_impl {
#[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 {
@ -2482,6 +2523,8 @@ macro_rules! int_impl {
/// ```
#[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 {
@ -2538,6 +2581,8 @@ macro_rules! int_impl {
/// ```
#[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()
@ -2556,6 +2601,8 @@ macro_rules! int_impl {
/// ```
#[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()
@ -2590,6 +2637,8 @@ macro_rules! int_impl {
#[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

View File

@ -198,6 +198,8 @@ macro_rules! nonzero_leading_trailing_zeros {
/// ```
#[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
@ -220,6 +222,8 @@ macro_rules! nonzero_leading_trailing_zeros {
/// ```
#[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
@ -315,6 +319,8 @@ macro_rules! nonzero_unsigned_operations {
/// # }
/// ```
#[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) {
@ -348,6 +354,8 @@ macro_rules! nonzero_unsigned_operations {
/// # }
/// ```
#[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
@ -378,6 +386,8 @@ macro_rules! nonzero_unsigned_operations {
/// # }
/// ```
#[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.
@ -410,6 +420,8 @@ macro_rules! nonzero_unsigned_operations {
/// # }
/// ```
#[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() {
@ -460,6 +472,8 @@ macro_rules! nonzero_signed_operations {
/// # }
/// ```
#[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.
@ -490,6 +504,8 @@ macro_rules! nonzero_signed_operations {
/// # }
/// ```
#[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() {
@ -524,6 +540,8 @@ macro_rules! nonzero_signed_operations {
/// # }
/// ```
#[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();
@ -562,6 +580,8 @@ macro_rules! nonzero_signed_operations {
/// # }
/// ```
#[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.
@ -595,6 +615,8 @@ macro_rules! nonzero_signed_operations {
/// # }
/// ```
#[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.
@ -628,6 +650,8 @@ macro_rules! nonzero_signed_operations {
/// # }
/// ```
#[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.
@ -675,6 +699,8 @@ macro_rules! nonzero_unsigned_signed_operations {
/// # }
/// ```
#[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()) {
@ -709,6 +735,8 @@ macro_rules! nonzero_unsigned_signed_operations {
/// # }
/// ```
#[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
@ -749,6 +777,8 @@ macro_rules! nonzero_unsigned_signed_operations {
/// # }
/// ```
#[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.
@ -778,6 +808,8 @@ macro_rules! nonzero_unsigned_signed_operations {
/// # }
/// ```
#[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) {
@ -820,6 +852,8 @@ macro_rules! nonzero_unsigned_signed_operations {
/// # }
/// ```
#[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

View File

@ -474,6 +474,8 @@ macro_rules! saturating_int_impl {
#[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()
@ -492,6 +494,8 @@ macro_rules! saturating_int_impl {
#[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()
@ -512,6 +516,8 @@ macro_rules! saturating_int_impl {
/// 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()
@ -538,6 +544,8 @@ macro_rules! saturating_int_impl {
/// 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))
@ -564,6 +572,8 @@ macro_rules! saturating_int_impl {
/// 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))
@ -588,6 +598,8 @@ macro_rules! saturating_int_impl {
/// 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())
@ -614,10 +626,11 @@ macro_rules! saturating_int_impl {
/// 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())
}
@ -699,6 +712,8 @@ macro_rules! saturating_int_impl {
/// ```
#[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())
}
@ -726,6 +741,8 @@ macro_rules! saturating_int_impl {
/// ```
#[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())
}
@ -754,6 +771,8 @@ macro_rules! saturating_int_impl {
/// ```
#[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))
}
@ -782,6 +801,8 @@ macro_rules! saturating_int_impl_signed {
/// ```
#[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()
}
@ -805,6 +826,8 @@ macro_rules! saturating_int_impl_signed {
/// ```
#[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())
}
@ -829,6 +852,8 @@ macro_rules! saturating_int_impl_signed {
/// ```
#[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())
}
@ -910,6 +935,8 @@ macro_rules! saturating_int_impl_unsigned {
/// ```
#[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()
}

View File

@ -80,6 +80,8 @@ macro_rules! uint_impl {
#[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
@ -96,6 +98,8 @@ macro_rules! uint_impl {
/// ```
#[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()
@ -114,6 +118,8 @@ macro_rules! uint_impl {
/// ```
#[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
@ -133,6 +139,8 @@ macro_rules! uint_impl {
/// ```
#[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
@ -151,6 +159,8 @@ macro_rules! uint_impl {
/// ```
#[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()
@ -170,6 +180,8 @@ macro_rules! uint_impl {
/// ```
#[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()
@ -238,6 +250,8 @@ macro_rules! uint_impl {
/// ```
#[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
@ -259,8 +273,9 @@ macro_rules! uint_impl {
/// ```
#[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
}
@ -349,6 +364,8 @@ macro_rules! uint_impl {
/// ```
#[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")]
@ -381,6 +398,8 @@ macro_rules! uint_impl {
/// ```
#[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")]
@ -678,7 +697,7 @@ macro_rules! uint_impl {
/// ```
#[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]
@ -711,7 +730,7 @@ macro_rules! uint_impl {
/// ```
#[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]
@ -744,7 +763,7 @@ macro_rules! uint_impl {
/// ```
#[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]
@ -779,7 +798,7 @@ macro_rules! uint_impl {
/// ```
#[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 {
@ -815,7 +834,7 @@ macro_rules! uint_impl {
/// ```
#[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 {
@ -839,7 +858,7 @@ macro_rules! uint_impl {
/// ```
#[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)
@ -860,6 +879,8 @@ macro_rules! uint_impl {
/// ```
#[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();
@ -1221,7 +1242,7 @@ macro_rules! uint_impl {
#[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)
@ -1346,6 +1367,8 @@ macro_rules! uint_impl {
/// ```
#[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)
@ -1601,6 +1624,8 @@ macro_rules! uint_impl {
#[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 {
@ -1775,6 +1800,8 @@ macro_rules! uint_impl {
#[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)
}
@ -1891,7 +1918,7 @@ macro_rules! uint_impl {
#[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 {
@ -1988,6 +2015,8 @@ macro_rules! uint_impl {
#[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 {
@ -2009,6 +2038,8 @@ macro_rules! uint_impl {
#[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 {
@ -2133,6 +2164,8 @@ macro_rules! uint_impl {
/// ```
#[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 {
@ -2155,6 +2188,8 @@ macro_rules! uint_impl {
#[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)
}
@ -2177,6 +2212,8 @@ macro_rules! uint_impl {
#[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)
}
@ -2194,6 +2231,8 @@ macro_rules! uint_impl {
/// ```
#[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()
@ -2212,6 +2251,8 @@ macro_rules! uint_impl {
/// ```
#[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()
@ -2244,6 +2285,8 @@ macro_rules! uint_impl {
/// ```
#[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]

View File

@ -469,6 +469,8 @@ macro_rules! wrapping_int_impl {
#[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()
@ -487,6 +489,8 @@ macro_rules! wrapping_int_impl {
#[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()
@ -507,6 +511,8 @@ macro_rules! wrapping_int_impl {
/// 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()
@ -533,6 +539,8 @@ macro_rules! wrapping_int_impl {
/// 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))
@ -559,6 +567,8 @@ macro_rules! wrapping_int_impl {
/// 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))
@ -583,6 +593,8 @@ macro_rules! wrapping_int_impl {
/// 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())
@ -610,8 +622,9 @@ macro_rules! wrapping_int_impl {
/// ```
#[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())
}
@ -692,6 +705,8 @@ macro_rules! wrapping_int_impl {
/// }
/// ```
#[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())
@ -719,6 +734,8 @@ macro_rules! wrapping_int_impl {
/// }
/// ```
#[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())
@ -747,6 +764,8 @@ macro_rules! wrapping_int_impl {
/// 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))
@ -775,6 +794,8 @@ macro_rules! wrapping_int_impl_signed {
/// 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()
@ -801,6 +822,8 @@ macro_rules! wrapping_int_impl_signed {
/// 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())
@ -825,6 +848,8 @@ macro_rules! wrapping_int_impl_signed {
#[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())
@ -895,6 +920,8 @@ macro_rules! wrapping_int_impl_unsigned {
/// 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()
@ -938,6 +965,8 @@ macro_rules! wrapping_int_impl_unsigned {
#[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 {

View File

@ -465,6 +465,8 @@ impl Duration {
/// 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> {
@ -498,6 +500,8 @@ impl 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 {
@ -521,6 +525,8 @@ impl 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> {
@ -552,6 +558,8 @@ impl 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 {
@ -575,6 +583,8 @@ impl 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> {
@ -604,6 +614,8 @@ impl 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 {
@ -628,6 +640,8 @@ impl 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> {
@ -815,6 +829,8 @@ impl 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 {
@ -837,6 +853,8 @@ impl 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 {
@ -858,6 +876,8 @@ impl 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 {
@ -881,6 +901,8 @@ impl 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 {
@ -899,6 +921,8 @@ impl 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 {
@ -917,6 +941,8 @@ impl Duration {
/// 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 {