@@ -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 {
@@ -151,7 +151,7 @@ macro_rules! nonzero_integer {
151151 /// Basic usage:
152152 ///
153153 /// ```
154- #[ doc = concat!( "let n = std::num::" , stringify!( $Ty) , "::new(" , stringify! ( $leading_zeros_test) , ").unwrap();" ) ]
154+ #[ doc = concat!( "let n = std::num::" , stringify!( $Ty) , "::new(" , $leading_zeros_test, ").unwrap();" ) ]
155155 ///
156156 /// assert_eq!(n.leading_zeros(), 0);
157157 /// ```
@@ -461,8 +461,7 @@ macro_rules! nonzero_integer {
461461 }
462462
463463 impl_nonzero_fmt! {
464- #[ stable( feature = $feature, since = $since) ]
465- ( Debug , Display , Binary , Octal , LowerHex , UpperHex ) for $Ty
464+ #[ $stability] ( Debug , Display , Binary , Octal , LowerHex , UpperHex ) for $Ty
466465 }
467466
468467 #[ stable( feature = "nonzero_parse" , since = "1.35.0" ) ]
@@ -478,6 +477,28 @@ macro_rules! nonzero_integer {
478477
479478 nonzero_integer_signedness_dependent_impls!( $Ty $signedness $Int) ;
480479 } ;
480+
481+ ( Self = $Ty: ident, Primitive = unsigned $Int: ident $( , ) ?) => {
482+ nonzero_integer! {
483+ #[ stable( feature = "nonzero" , since = "1.28.0" ) ]
484+ #[ rustc_const_stable( feature = "nonzero" , since = "1.28.0" ) ]
485+ Self = $Ty,
486+ Primitive = unsigned $Int,
487+ UnsignedPrimitive = $Int,
488+ leading_zeros_test = concat!( stringify!( $Int) , "::MAX" ) ,
489+ }
490+ } ;
491+
492+ ( Self = $Ty: ident, Primitive = signed $Int: ident, $( $rest: tt) * ) => {
493+ nonzero_integer! {
494+ #[ stable( feature = "signed_nonzero" , since = "1.34.0" ) ]
495+ #[ rustc_const_stable( feature = "signed_nonzero" , since = "1.34.0" ) ]
496+ Self = $Ty,
497+ Primitive = signed $Int,
498+ $( $rest) *
499+ leading_zeros_test = concat!( "-1" , stringify!( $Int) ) ,
500+ }
501+ } ;
481502}
482503
483504macro_rules! nonzero_integer_signedness_dependent_impls {
@@ -1253,113 +1274,71 @@ macro_rules! sign_dependent_expr {
12531274nonzero_integer ! {
12541275 Self = NonZeroU8 ,
12551276 Primitive = unsigned u8 ,
1256- UnsignedPrimitive = u8 ,
1257- feature = "nonzero" ,
1258- original_stabilization = "1.28.0" ,
1259- leading_zeros_test = u8 :: MAX ,
12601277}
12611278
12621279nonzero_integer ! {
12631280 Self = NonZeroU16 ,
12641281 Primitive = unsigned u16 ,
1265- UnsignedPrimitive = u16 ,
1266- feature = "nonzero" ,
1267- original_stabilization = "1.28.0" ,
1268- leading_zeros_test = u16 :: MAX ,
12691282}
12701283
12711284nonzero_integer ! {
12721285 Self = NonZeroU32 ,
12731286 Primitive = unsigned u32 ,
1274- UnsignedPrimitive = u32 ,
1275- feature = "nonzero" ,
1276- original_stabilization = "1.28.0" ,
1277- leading_zeros_test = u32 :: MAX ,
12781287}
12791288
12801289nonzero_integer ! {
12811290 Self = NonZeroU64 ,
12821291 Primitive = unsigned u64 ,
1283- UnsignedPrimitive = u64 ,
1284- feature = "nonzero" ,
1285- original_stabilization = "1.28.0" ,
1286- leading_zeros_test = u64 :: MAX ,
12871292}
12881293
12891294nonzero_integer ! {
12901295 Self = NonZeroU128 ,
12911296 Primitive = unsigned u128 ,
1292- UnsignedPrimitive = u128 ,
1293- feature = "nonzero" ,
1294- original_stabilization = "1.28.0" ,
1295- leading_zeros_test = u128 :: MAX ,
12961297}
12971298
12981299nonzero_integer ! {
12991300 Self = NonZeroUsize ,
13001301 Primitive = unsigned usize ,
1301- UnsignedPrimitive = usize ,
1302- feature = "nonzero" ,
1303- original_stabilization = "1.28.0" ,
1304- leading_zeros_test = usize :: MAX ,
13051302}
13061303
13071304nonzero_integer ! {
13081305 Self = NonZeroI8 ,
13091306 Primitive = signed i8 ,
13101307 UnsignedNonZero = NonZeroU8 ,
13111308 UnsignedPrimitive = u8 ,
1312- feature = "signed_nonzero" ,
1313- original_stabilization = "1.34.0" ,
1314- leading_zeros_test = -1i8 ,
13151309}
13161310
13171311nonzero_integer ! {
13181312 Self = NonZeroI16 ,
13191313 Primitive = signed i16 ,
13201314 UnsignedNonZero = NonZeroU16 ,
13211315 UnsignedPrimitive = u16 ,
1322- feature = "signed_nonzero" ,
1323- original_stabilization = "1.34.0" ,
1324- leading_zeros_test = -1i16 ,
13251316}
13261317
13271318nonzero_integer ! {
13281319 Self = NonZeroI32 ,
13291320 Primitive = signed i32 ,
13301321 UnsignedNonZero = NonZeroU32 ,
13311322 UnsignedPrimitive = u32 ,
1332- feature = "signed_nonzero" ,
1333- original_stabilization = "1.34.0" ,
1334- leading_zeros_test = -1i32 ,
13351323}
13361324
13371325nonzero_integer ! {
13381326 Self = NonZeroI64 ,
13391327 Primitive = signed i64 ,
13401328 UnsignedNonZero = NonZeroU64 ,
13411329 UnsignedPrimitive = u64 ,
1342- feature = "signed_nonzero" ,
1343- original_stabilization = "1.34.0" ,
1344- leading_zeros_test = -1i64 ,
13451330}
13461331
13471332nonzero_integer ! {
13481333 Self = NonZeroI128 ,
13491334 Primitive = signed i128 ,
13501335 UnsignedNonZero = NonZeroU128 ,
13511336 UnsignedPrimitive = u128 ,
1352- feature = "signed_nonzero" ,
1353- original_stabilization = "1.34.0" ,
1354- leading_zeros_test = -1i128 ,
13551337}
13561338
13571339nonzero_integer ! {
13581340 Self = NonZeroIsize ,
13591341 Primitive = signed isize ,
13601342 UnsignedNonZero = NonZeroUsize ,
13611343 UnsignedPrimitive = usize ,
1362- feature = "signed_nonzero" ,
1363- original_stabilization = "1.34.0" ,
1364- leading_zeros_test = -1isize ,
13651344}
0 commit comments