about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTim 'Piepmatz' Hesse <git+github@cptpiepmatz.de>2025-09-25 17:52:24 +0200
committerTim 'Piepmatz' Hesse <git+github@cptpiepmatz.de>2025-09-25 17:52:24 +0200
commit185ae698aabe0f6f7cc5ef7eeed13a556bce5334 (patch)
treedf0200fc33c896b18af8079036a1d4fab6cbf3f4
parentf6092f224d2b1774b31033f12d0bee626943b02f (diff)
downloadrust-185ae698aabe0f6f7cc5ef7eeed13a556bce5334.tar.gz
rust-185ae698aabe0f6f7cc5ef7eeed13a556bce5334.zip
add doc for `NonZero*` const creation
-rw-r--r--library/core/src/num/nonzero.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs
index 1b7c28bb95a..d9184e3c9c2 100644
--- a/library/core/src/num/nonzero.rs
+++ b/library/core/src/num/nonzero.rs
@@ -548,6 +548,18 @@ macro_rules! nonzero_integer {
         #[doc = concat!("assert_eq!(align_of::<", stringify!($Ty), ">(), align_of::<Option<", stringify!($Ty), ">>());")]
         /// ```
         ///
+        /// # Compile-time creation
+        ///
+        /// Since both [`Option::unwrap()`] and [`Option::expect()`] are `const`, it is possible to
+        /// define a new
+        #[doc = concat!("`", stringify!($Ty), "`")]
+        /// at compile time via:
+        /// ```
+        #[doc = concat!("use std::num::", stringify!($Ty), ";")]
+        ///
+        #[doc = concat!("const TEN: ", stringify!($Ty), " = ", stringify!($Ty) , r#"::new(10).expect("ten is non-zero");"#)]
+        /// ```
+        ///
         /// [null pointer optimization]: crate::option#representation
         #[$stability]
         pub type $Ty = NonZero<$Int>;