Skip to content

Commit 22342b0

Browse files
committed
doc(std): clarify NonZero<T> usage limitation in doc comment
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
1 parent bc4376f commit 22342b0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

library/core/src/num/nonzero.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ impl_zeroable_primitive!(
111111
/// ```
112112
///
113113
/// [null pointer optimization]: crate::option#representation
114+
///
115+
/// # Note on generic usage
116+
///
117+
/// `NonZero<T>` can only be used with some standard library primitive types
118+
/// (such as `u8`, `i32`, and etc.). The type parameter `T` must implement the
119+
/// internal trait [`ZeroablePrimitive`], which is currently permanently unstable
120+
/// and cannot be implemented by users. Therefore, you cannot use `NonZero<T>`
121+
/// with your own types, nor can you implement traits for all `NonZero<T>`,
122+
/// only for concrete types.
114123
#[stable(feature = "generic_nonzero", since = "1.79.0")]
115124
#[repr(transparent)]
116125
#[rustc_nonnull_optimization_guaranteed]

0 commit comments

Comments
 (0)