@@ -34,22 +34,32 @@ macro_rules! impl_nonzero_fmt {
3434 }
3535}
3636
37+ macro_rules! doc_comment {
38+ ( $x: expr, $( $tt: tt) * ) => {
39+ #[ doc = $x]
40+ $( $tt) *
41+ } ;
42+ }
43+
3744macro_rules! nonzero_integers {
3845 ( $( $Ty: ident( $Int: ty) ; ) + ) => {
3946 $(
40- /// An integer that is known not to equal zero.
41- ///
42- /// This enables some memory layout optimization.
43- /// For example, `Option<NonZeroU32>` is the same size as `u32`:
44- ///
45- /// ```rust
46- /// use std::mem::size_of;
47- /// assert_eq!(size_of::<Option<std::num::NonZeroU32>>(), size_of::<u32>());
48- /// ```
49- #[ stable( feature = "nonzero" , since = "1.28.0" ) ]
50- #[ derive( Copy , Clone , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
51- #[ repr( transparent) ]
52- pub struct $Ty( NonZero <$Int>) ;
47+ doc_comment! {
48+ concat!( "An integer that is known not to equal zero.
49+
50+ This enables some memory layout optimization.
51+ For example, `Option<" , stringify!( $Ty) , ">` is the same size as `" , stringify!( $Int) , "`:
52+
53+ ```rust
54+ use std::mem::size_of;
55+ assert_eq!(size_of::<Option<std::num::" , stringify!( $Ty) , ">>(), size_of::<" , stringify!( $Int) ,
56+ ">());
57+ ```" ) ,
58+ #[ stable( feature = "nonzero" , since = "1.28.0" ) ]
59+ #[ derive( Copy , Clone , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
60+ #[ repr( transparent) ]
61+ pub struct $Ty( NonZero <$Int>) ;
62+ }
5363
5464 impl $Ty {
5565 /// Create a non-zero without checking the value.
@@ -176,13 +186,6 @@ pub mod dec2flt;
176186pub mod bignum;
177187pub mod diy_float;
178188
179- macro_rules! doc_comment {
180- ( $x: expr, $( $tt: tt) * ) => {
181- #[ doc = $x]
182- $( $tt) *
183- } ;
184- }
185-
186189mod wrapping;
187190
188191// `Int` + `SignedInt` implemented for signed integers
0 commit comments