@@ -24,12 +24,12 @@ macro_rules! impl_nonzero_fmt {
2424
2525macro_rules! nonzero_integer {
2626 (
27+ #[ $stability: meta]
28+ #[ $const_new_unchecked_stability: meta]
2729 Self = $Ty: ident,
2830 Primitive = $signedness: ident $Int: ident,
2931 $( UnsignedNonZero = $UnsignedNonZero: ident, ) ?
3032 UnsignedPrimitive = $UnsignedPrimitive: ty,
31- feature = $feature: literal,
32- original_stabilization = $since: literal,
3333
3434 // Used in doc comments.
3535 leading_zeros_test = $leading_zeros_test: expr,
@@ -64,7 +64,7 @@ macro_rules! nonzero_integer {
6464 /// ```
6565 ///
6666 /// [null pointer optimization]: crate::option#representation
67- #[ stable ( feature = $feature , since = $since ) ]
67+ #[ $stability ]
6868 #[ derive( Copy , Clone , Eq , PartialEq , Ord , PartialOrd , Hash ) ]
6969 #[ repr( transparent) ]
7070 #[ rustc_layout_scalar_valid_range_start( 1 ) ]
@@ -79,8 +79,8 @@ macro_rules! nonzero_integer {
7979 /// # Safety
8080 ///
8181 /// The value must not be zero.
82- #[ stable ( feature = $feature , since = $since ) ]
83- #[ rustc_const_stable ( feature = $feature , since = $since ) ]
82+ #[ $stability ]
83+ #[ $const_new_unchecked_stability ]
8484 #[ must_use]
8585 #[ inline]
8686 pub const unsafe fn new_unchecked( n: $Int) -> Self {
@@ -95,7 +95,7 @@ macro_rules! nonzero_integer {
9595 }
9696
9797 /// Creates a non-zero if the given value is not zero.
98- #[ stable ( feature = $feature , since = $since ) ]
98+ #[ $stability ]
9999 #[ rustc_const_stable( feature = "const_nonzero_int_methods" , since = "1.47.0" ) ]
100100 #[ must_use]
101101 #[ inline]
@@ -109,7 +109,7 @@ macro_rules! nonzero_integer {
109109 }
110110
111111 /// Returns the value as a primitive type.
112- #[ stable ( feature = $feature , since = $since ) ]
112+ #[ $stability ]
113113 #[ inline]
114114 #[ rustc_const_stable( feature = "const_nonzero_get" , since = "1.34.0" ) ]
115115 pub const fn get( self ) -> $Int {
@@ -139,7 +139,7 @@ macro_rules! nonzero_integer {
139139 /// Basic usage:
140140 ///
141141 /// ```
142- #[ doc = concat!( "let n = std::num::" , stringify!( $Ty) , "::new(" , stringify! ( $leading_zeros_test) , ").unwrap();" ) ]
142+ #[ doc = concat!( "let n = std::num::" , stringify!( $Ty) , "::new(" , $leading_zeros_test, ").unwrap();" ) ]
143143 ///
144144 /// assert_eq!(n.leading_zeros(), 0);
145145 /// ```
@@ -447,8 +447,7 @@ macro_rules! nonzero_integer {
447447 }
448448
449449 impl_nonzero_fmt! {
450- #[ stable( feature = $feature, since = $since) ]
451- ( Debug , Display , Binary , Octal , LowerHex , UpperHex ) for $Ty
450+ #[ $stability] ( Debug , Display , Binary , Octal , LowerHex , UpperHex ) for $Ty
452451 }
453452
454453 #[ stable( feature = "nonzero_parse" , since = "1.35.0" ) ]
@@ -464,6 +463,28 @@ macro_rules! nonzero_integer {
464463
465464 nonzero_integer_signedness_dependent_impls!( $Ty $signedness $Int) ;
466465 } ;
466+
467+ ( Self = $Ty: ident, Primitive = unsigned $Int: ident $( , ) ?) => {
468+ nonzero_integer! {
469+ #[ stable( feature = "nonzero" , since = "1.28.0" ) ]
470+ #[ rustc_const_stable( feature = "nonzero" , since = "1.28.0" ) ]
471+ Self = $Ty,
472+ Primitive = unsigned $Int,
473+ UnsignedPrimitive = $Int,
474+ leading_zeros_test = concat!( stringify!( $Int) , "::MAX" ) ,
475+ }
476+ } ;
477+
478+ ( Self = $Ty: ident, Primitive = signed $Int: ident, $( $rest: tt) * ) => {
479+ nonzero_integer! {
480+ #[ stable( feature = "signed_nonzero" , since = "1.34.0" ) ]
481+ #[ rustc_const_stable( feature = "signed_nonzero" , since = "1.34.0" ) ]
482+ Self = $Ty,
483+ Primitive = signed $Int,
484+ $( $rest) *
485+ leading_zeros_test = concat!( "-1" , stringify!( $Int) ) ,
486+ }
487+ } ;
467488}
468489
469490macro_rules! nonzero_integer_signedness_dependent_impls {
@@ -1239,113 +1260,71 @@ macro_rules! sign_dependent_expr {
12391260nonzero_integer ! {
12401261 Self = NonZeroU8 ,
12411262 Primitive = unsigned u8 ,
1242- UnsignedPrimitive = u8 ,
1243- feature = "nonzero" ,
1244- original_stabilization = "1.28.0" ,
1245- leading_zeros_test = u8 :: MAX ,
12461263}
12471264
12481265nonzero_integer ! {
12491266 Self = NonZeroU16 ,
12501267 Primitive = unsigned u16 ,
1251- UnsignedPrimitive = u16 ,
1252- feature = "nonzero" ,
1253- original_stabilization = "1.28.0" ,
1254- leading_zeros_test = u16 :: MAX ,
12551268}
12561269
12571270nonzero_integer ! {
12581271 Self = NonZeroU32 ,
12591272 Primitive = unsigned u32 ,
1260- UnsignedPrimitive = u32 ,
1261- feature = "nonzero" ,
1262- original_stabilization = "1.28.0" ,
1263- leading_zeros_test = u32 :: MAX ,
12641273}
12651274
12661275nonzero_integer ! {
12671276 Self = NonZeroU64 ,
12681277 Primitive = unsigned u64 ,
1269- UnsignedPrimitive = u64 ,
1270- feature = "nonzero" ,
1271- original_stabilization = "1.28.0" ,
1272- leading_zeros_test = u64 :: MAX ,
12731278}
12741279
12751280nonzero_integer ! {
12761281 Self = NonZeroU128 ,
12771282 Primitive = unsigned u128 ,
1278- UnsignedPrimitive = u128 ,
1279- feature = "nonzero" ,
1280- original_stabilization = "1.28.0" ,
1281- leading_zeros_test = u128 :: MAX ,
12821283}
12831284
12841285nonzero_integer ! {
12851286 Self = NonZeroUsize ,
12861287 Primitive = unsigned usize ,
1287- UnsignedPrimitive = usize ,
1288- feature = "nonzero" ,
1289- original_stabilization = "1.28.0" ,
1290- leading_zeros_test = usize :: MAX ,
12911288}
12921289
12931290nonzero_integer ! {
12941291 Self = NonZeroI8 ,
12951292 Primitive = signed i8 ,
12961293 UnsignedNonZero = NonZeroU8 ,
12971294 UnsignedPrimitive = u8 ,
1298- feature = "signed_nonzero" ,
1299- original_stabilization = "1.34.0" ,
1300- leading_zeros_test = -1i8 ,
13011295}
13021296
13031297nonzero_integer ! {
13041298 Self = NonZeroI16 ,
13051299 Primitive = signed i16 ,
13061300 UnsignedNonZero = NonZeroU16 ,
13071301 UnsignedPrimitive = u16 ,
1308- feature = "signed_nonzero" ,
1309- original_stabilization = "1.34.0" ,
1310- leading_zeros_test = -1i16 ,
13111302}
13121303
13131304nonzero_integer ! {
13141305 Self = NonZeroI32 ,
13151306 Primitive = signed i32 ,
13161307 UnsignedNonZero = NonZeroU32 ,
13171308 UnsignedPrimitive = u32 ,
1318- feature = "signed_nonzero" ,
1319- original_stabilization = "1.34.0" ,
1320- leading_zeros_test = -1i32 ,
13211309}
13221310
13231311nonzero_integer ! {
13241312 Self = NonZeroI64 ,
13251313 Primitive = signed i64 ,
13261314 UnsignedNonZero = NonZeroU64 ,
13271315 UnsignedPrimitive = u64 ,
1328- feature = "signed_nonzero" ,
1329- original_stabilization = "1.34.0" ,
1330- leading_zeros_test = -1i64 ,
13311316}
13321317
13331318nonzero_integer ! {
13341319 Self = NonZeroI128 ,
13351320 Primitive = signed i128 ,
13361321 UnsignedNonZero = NonZeroU128 ,
13371322 UnsignedPrimitive = u128 ,
1338- feature = "signed_nonzero" ,
1339- original_stabilization = "1.34.0" ,
1340- leading_zeros_test = -1i128 ,
13411323}
13421324
13431325nonzero_integer ! {
13441326 Self = NonZeroIsize ,
13451327 Primitive = signed isize ,
13461328 UnsignedNonZero = NonZeroUsize ,
13471329 UnsignedPrimitive = usize ,
1348- feature = "signed_nonzero" ,
1349- original_stabilization = "1.34.0" ,
1350- leading_zeros_test = -1isize ,
13511330}
0 commit comments