diff options
| author | Markus Reiter <me@reitermark.us> | 2024-02-18 21:29:24 +0100 |
|---|---|---|
| committer | Markus Reiter <me@reitermark.us> | 2024-02-22 15:17:33 +0100 |
| commit | 14ed426eec6939737ea320e50bb28d239c7aee93 (patch) | |
| tree | 8a5ec0d0fb9fcb6b540d4a6ce54289f84850d7f9 /library/core/src/num | |
| parent | 52dba5ffe73c25951fd6ae38bf20513002dd7874 (diff) | |
Use generic `NonZero` everywhere in `core`.
Diffstat (limited to 'library/core/src/num')
| -rw-r--r-- | library/core/src/num/nonzero.rs | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index 8943e2f0e2a..295b88361cf 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -23,7 +23,7 @@ mod private { /// A marker trait for primitive types which can be zero. /// -/// This is an implementation detail for [`NonZero<T>`](NonZero) which may disappear or be replaced at any time. +/// This is an implementation detail for <code>[NonZero]\<T></code> which may disappear or be replaced at any time. #[unstable( feature = "nonzero_internals", reason = "implementation detail which may disappear or be replaced at any time", @@ -507,18 +507,16 @@ macro_rules! nonzero_integer { /// Basic usage: /// /// ``` - /// #![feature(non_zero_count_ones)] + /// #![feature(generic_nonzero, non_zero_count_ones)] /// # fn main() { test().unwrap(); } /// # fn test() -> Option<()> { /// # use std::num::*; /// # - /// let one = NonZeroU32::new(1)?; - /// let three = NonZeroU32::new(3)?; - #[doc = concat!("let a = ", stringify!($Ty), "::new(0b100_0000)?;")] - #[doc = concat!("let b = ", stringify!($Ty), "::new(0b100_0011)?;")] + #[doc = concat!("let a = NonZero::<", stringify!($Int), ">::new(0b100_0000)?;")] + #[doc = concat!("let b = NonZero::<", stringify!($Int), ">::new(0b100_0011)?;")] /// - /// assert_eq!(a.count_ones(), one); - /// assert_eq!(b.count_ones(), three); + /// assert_eq!(a.count_ones(), NonZero::new(1)?); + /// assert_eq!(b.count_ones(), NonZero::new(3)?); /// # Some(()) /// # } /// ``` @@ -530,7 +528,7 @@ macro_rules! nonzero_integer { #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline(always)] - pub const fn count_ones(self) -> NonZeroU32 { + pub const fn count_ones(self) -> NonZero<u32> { // SAFETY: // `self` is non-zero, which means it has at least one bit set, which means // that the result of `count_ones` is non-zero. |
