@@ -10,9 +10,9 @@ use ops;
10
10
use str:: FromStr ;
11
11
12
12
macro_rules! impl_nonzero_fmt {
13
- ( ( $( $Trait: ident ) ,+ ) for $Ty: ident ) => {
13
+ ( # [ $stability : meta ] ( $( $Trait: ident ) ,+ ) for $Ty: ident ) => {
14
14
$(
15
- #[ stable ( feature = "nonzero" , since = "1.28.0" ) ]
15
+ #[ $stability ]
16
16
impl fmt:: $Trait for $Ty {
17
17
#[ inline]
18
18
fn fmt( & self , f: & mut fmt:: Formatter ) -> fmt:: Result {
@@ -31,7 +31,7 @@ macro_rules! doc_comment {
31
31
}
32
32
33
33
macro_rules! nonzero_integers {
34
- ( $( $Ty: ident( $Int: ty) ; ) + ) => {
34
+ ( $( # [ $stability : meta ] $Ty: ident( $Int: ty) ; ) + ) => {
35
35
$(
36
36
doc_comment! {
37
37
concat!( "An integer that is known not to equal zero.
@@ -41,10 +41,10 @@ For example, `Option<", stringify!($Ty), ">` is the same size as `", stringify!(
41
41
42
42
```rust
43
43
use std::mem::size_of;
44
- assert_eq!(size_of::<Option<std ::num::" , stringify!( $Ty) , ">>(), size_of::<" , stringify!( $Int) ,
44
+ assert_eq!(size_of::<Option<core ::num::" , stringify!( $Ty) , ">>(), size_of::<" , stringify!( $Int) ,
45
45
">());
46
46
```" ) ,
47
- #[ stable ( feature = "nonzero" , since = "1.28.0" ) ]
47
+ #[ $stability ]
48
48
#[ derive( Copy , Clone , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
49
49
#[ repr( transparent) ]
50
50
#[ rustc_layout_scalar_valid_range_start( 1 ) ]
@@ -57,14 +57,14 @@ assert_eq!(size_of::<Option<std::num::", stringify!($Ty), ">>(), size_of::<", st
57
57
/// # Safety
58
58
///
59
59
/// The value must not be zero.
60
- #[ stable ( feature = "nonzero" , since = "1.28.0" ) ]
60
+ #[ $stability ]
61
61
#[ inline]
62
62
pub const unsafe fn new_unchecked( n: $Int) -> Self {
63
63
$Ty( n)
64
64
}
65
65
66
66
/// Create a non-zero if the given value is not zero.
67
- #[ stable ( feature = "nonzero" , since = "1.28.0" ) ]
67
+ #[ $stability ]
68
68
#[ inline]
69
69
pub fn new( n: $Int) -> Option <Self > {
70
70
if n != 0 {
@@ -75,7 +75,7 @@ assert_eq!(size_of::<Option<std::num::", stringify!($Ty), ">>(), size_of::<", st
75
75
}
76
76
77
77
/// Returns the value as a primitive type.
78
- #[ stable ( feature = "nonzero" , since = "1.28.0" ) ]
78
+ #[ $stability ]
79
79
#[ inline]
80
80
pub const fn get( self ) -> $Int {
81
81
self . 0
@@ -91,19 +91,25 @@ assert_eq!(size_of::<Option<std::num::", stringify!($Ty), ">>(), size_of::<", st
91
91
}
92
92
93
93
impl_nonzero_fmt! {
94
- ( Debug , Display , Binary , Octal , LowerHex , UpperHex ) for $Ty
94
+ # [ $stability ] ( Debug , Display , Binary , Octal , LowerHex , UpperHex ) for $Ty
95
95
}
96
96
) +
97
97
}
98
98
}
99
99
100
100
nonzero_integers ! {
101
- NonZeroU8 ( u8 ) ;
102
- NonZeroU16 ( u16 ) ;
103
- NonZeroU32 ( u32 ) ;
104
- NonZeroU64 ( u64 ) ;
105
- NonZeroU128 ( u128 ) ;
106
- NonZeroUsize ( usize ) ;
101
+ #[ stable( feature = "nonzero" , since = "1.28.0" ) ] NonZeroU8 ( u8 ) ;
102
+ #[ stable( feature = "nonzero" , since = "1.28.0" ) ] NonZeroU16 ( u16 ) ;
103
+ #[ stable( feature = "nonzero" , since = "1.28.0" ) ] NonZeroU32 ( u32 ) ;
104
+ #[ stable( feature = "nonzero" , since = "1.28.0" ) ] NonZeroU64 ( u64 ) ;
105
+ #[ stable( feature = "nonzero" , since = "1.28.0" ) ] NonZeroU128 ( u128 ) ;
106
+ #[ stable( feature = "nonzero" , since = "1.28.0" ) ] NonZeroUsize ( usize ) ;
107
+ #[ stable( feature = "signed_nonzero" , since = "1.34.0" ) ] NonZeroI8 ( i8 ) ;
108
+ #[ stable( feature = "signed_nonzero" , since = "1.34.0" ) ] NonZeroI16 ( i16 ) ;
109
+ #[ stable( feature = "signed_nonzero" , since = "1.34.0" ) ] NonZeroI32 ( i32 ) ;
110
+ #[ stable( feature = "signed_nonzero" , since = "1.34.0" ) ] NonZeroI64 ( i64 ) ;
111
+ #[ stable( feature = "signed_nonzero" , since = "1.34.0" ) ] NonZeroI128 ( i128 ) ;
112
+ #[ stable( feature = "signed_nonzero" , since = "1.34.0" ) ] NonZeroIsize ( isize ) ;
107
113
}
108
114
109
115
/// Provides intentionally-wrapped arithmetic on `T`.
0 commit comments