Skip to content

Commit

Permalink
For NonZero impl macros, give unsigned impls access to the correspond…
Browse files Browse the repository at this point in the history
…ing signed type

There was a macro parameter giving signed impls access to the
corresponding unsigned type, but not the other way around.

This will allow implementing methods converting in both directions.
  • Loading branch information
joshtriplett authored and gitbot committed Feb 20, 2025
1 parent 3145ee6 commit 01e4bd7
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions core/src/num/nonzero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ macro_rules! nonzero_integer {
#[$stability:meta]
Self = $Ty:ident,
Primitive = $signedness:ident $Int:ident,
SignedPrimitive = $Sint:ty,
UnsignedPrimitive = $Uint:ty,

// Used in doc comments.
Expand Down Expand Up @@ -905,6 +906,7 @@ macro_rules! nonzero_integer {

nonzero_integer_signedness_dependent_methods! {
Primitive = $signedness $Int,
SignedPrimitive = $Sint,
UnsignedPrimitive = $Uint,
}

Expand Down Expand Up @@ -1128,6 +1130,7 @@ macro_rules! nonzero_integer {
(
Self = $Ty:ident,
Primitive = unsigned $Int:ident,
SignedPrimitive = $Sint:ident,
rot = $rot:literal,
rot_op = $rot_op:literal,
rot_result = $rot_result:literal,
Expand All @@ -1140,6 +1143,7 @@ macro_rules! nonzero_integer {
#[stable(feature = "nonzero", since = "1.28.0")]
Self = $Ty,
Primitive = unsigned $Int,
SignedPrimitive = $Sint,
UnsignedPrimitive = $Int,
rot = $rot,
rot_op = $rot_op,
Expand All @@ -1154,7 +1158,7 @@ macro_rules! nonzero_integer {
(
Self = $Ty:ident,
Primitive = signed $Int:ident,
UnsignedPrimitive = $UInt:ident,
UnsignedPrimitive = $Uint:ident,
rot = $rot:literal,
rot_op = $rot_op:literal,
rot_result = $rot_result:literal,
Expand All @@ -1166,7 +1170,8 @@ macro_rules! nonzero_integer {
#[stable(feature = "signed_nonzero", since = "1.34.0")]
Self = $Ty,
Primitive = signed $Int,
UnsignedPrimitive = $UInt,
SignedPrimitive = $Int,
UnsignedPrimitive = $Uint,
rot = $rot,
rot_op = $rot_op,
rot_result = $rot_result,
Expand Down Expand Up @@ -1286,6 +1291,7 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
// Associated items for unsigned nonzero types only.
(
Primitive = unsigned $Int:ident,
SignedPrimitive = $Sint:ty,
UnsignedPrimitive = $Uint:ty,
) => {
/// The smallest value that can be represented by this non-zero
Expand Down Expand Up @@ -1625,6 +1631,7 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
// Associated items for signed nonzero types only.
(
Primitive = signed $Int:ident,
SignedPrimitive = $Sint:ty,
UnsignedPrimitive = $Uint:ty,
) => {
/// The smallest value that can be represented by this non-zero
Expand Down Expand Up @@ -2041,6 +2048,7 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
nonzero_integer! {
Self = NonZeroU8,
Primitive = unsigned u8,
SignedPrimitive = i8,
rot = 2,
rot_op = "0x82",
rot_result = "0xa",
Expand All @@ -2052,6 +2060,7 @@ nonzero_integer! {
nonzero_integer! {
Self = NonZeroU16,
Primitive = unsigned u16,
SignedPrimitive = i16,
rot = 4,
rot_op = "0xa003",
rot_result = "0x3a",
Expand All @@ -2063,6 +2072,7 @@ nonzero_integer! {
nonzero_integer! {
Self = NonZeroU32,
Primitive = unsigned u32,
SignedPrimitive = i32,
rot = 8,
rot_op = "0x10000b3",
rot_result = "0xb301",
Expand All @@ -2074,6 +2084,7 @@ nonzero_integer! {
nonzero_integer! {
Self = NonZeroU64,
Primitive = unsigned u64,
SignedPrimitive = i64,
rot = 12,
rot_op = "0xaa00000000006e1",
rot_result = "0x6e10aa",
Expand All @@ -2085,6 +2096,7 @@ nonzero_integer! {
nonzero_integer! {
Self = NonZeroU128,
Primitive = unsigned u128,
SignedPrimitive = i128,
rot = 16,
rot_op = "0x13f40000000000000000000000004f76",
rot_result = "0x4f7613f4",
Expand All @@ -2097,6 +2109,7 @@ nonzero_integer! {
nonzero_integer! {
Self = NonZeroUsize,
Primitive = unsigned usize,
SignedPrimitive = isize,
rot = 4,
rot_op = "0xa003",
rot_result = "0x3a",
Expand All @@ -2109,6 +2122,7 @@ nonzero_integer! {
nonzero_integer! {
Self = NonZeroUsize,
Primitive = unsigned usize,
SignedPrimitive = isize,
rot = 8,
rot_op = "0x10000b3",
rot_result = "0xb301",
Expand All @@ -2121,6 +2135,7 @@ nonzero_integer! {
nonzero_integer! {
Self = NonZeroUsize,
Primitive = unsigned usize,
SignedPrimitive = isize,
rot = 12,
rot_op = "0xaa00000000006e1",
rot_result = "0x6e10aa",
Expand Down

0 comments on commit 01e4bd7

Please sign in to comment.