Skip to content

Commit 0742569

Browse files
authored
Rollup merge of #143130 - xizheyin:142966, r=ibraheemdev
doc(std): clarify `NonZero<T>` usage limitation in doc comment Closes #142966 This PR clarifies `NonZero<T>` usage limitation in doc comment and fixes a typo. r? libs
2 parents 8df4a58 + 22342b0 commit 0742569

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)