Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions library/core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,8 +1280,6 @@ macro_rules! nonzero_integer {
/// # Examples
///
/// ```
/// #![feature(nonzero_ops)]
///
/// # use std::num::NonZero;
/// #
/// # fn main() { test().unwrap(); }
Expand All @@ -1295,12 +1293,17 @@ macro_rules! nonzero_integer {
/// ```
///
/// [`checked_mul`]: Self::checked_mul
#[unstable(feature = "nonzero_ops", issue = "84186")]
#[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const unsafe fn unchecked_mul(self, other: Self) -> Self {
// SAFETY: The caller ensures there is no overflow.
// SAFETY:
// - the caller promises that the multiplication does not overflow;
// - `self` and `other` are non-zero;
// - the only way to get zero from a multiplication without overflow
// is for either factor to be zero.
unsafe { Self::new_unchecked(self.get().unchecked_mul(other.get())) }
}

Expand Down Expand Up @@ -1872,8 +1875,6 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
/// # Examples
///
/// ```
/// #![feature(nonzero_ops)]
///
/// # use std::num::NonZero;
/// #
/// # fn main() { test().unwrap(); }
Expand All @@ -1887,12 +1888,17 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
/// ```
///
/// [`checked_add`]: Self::checked_add
#[unstable(feature = "nonzero_ops", issue = "84186")]
#[stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "nonzero_ops", since = "CURRENT_RUSTC_VERSION")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const unsafe fn unchecked_add(self, other: $Int) -> Self {
// SAFETY: The caller ensures there is no overflow.
// SAFETY:
// - the caller promises that the addition does not overflow;
// - `self` is non-zero;
// - the only way to get zero from an addition without overflow is
// for both addends to be zero.
unsafe { Self::new_unchecked(self.get().unchecked_add(other)) }
}

Expand Down
Loading