Skip to content

Commit 51bb2f7

Browse files
committed
doc(std): clarify NonZero<T> usage limitation in doc comment
Signed-off-by: xizheyin <[email protected]>
1 parent bc4376f commit 51bb2f7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

library/core/src/num/nonzero.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ impl_zeroable_primitive!(
111111
/// ```
112112
///
113113
/// [null pointer optimization]: crate::option#representation
114+
///
115+
/// **Note:** `NonZero<T>` can only be used with standard library primitive integer
116+
/// types (such as u8, i32, etc.). The type parameter T must implement the internal
117+
/// trait `ZeroablePrimitive`, which is currently permanently unstable and cannot be
118+
/// implemented by users. Therefore, you cannot use `NonZero<T>` with your own types,
119+
/// nor can you implement traits for all `NonZero<T>`, only for concrete types.
114120
#[stable(feature = "generic_nonzero", since = "1.79.0")]
115121
#[repr(transparent)]
116122
#[rustc_nonnull_optimization_guaranteed]
@@ -1472,7 +1478,7 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
14721478

14731479
/// Returns the smallest power of two greater than or equal to `self`.
14741480
/// Checks for overflow and returns [`None`]
1475-
/// if the next power of two is greater than the types maximum value.
1481+
/// if the next power of two is greater than the type's maximum value.
14761482
/// As a consequence, the result cannot wrap to zero.
14771483
///
14781484
/// # Examples

0 commit comments

Comments
 (0)