Skip to content

Commit c703b7e

Browse files
joshtriplettgitbot
authored and
gitbot
committed
For NonZero impl macros, give unsigned impls access to the corresponding 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.
1 parent 73bcab9 commit c703b7e

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

core/src/num/nonzero.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ macro_rules! nonzero_integer {
474474
#[$stability:meta]
475475
Self = $Ty:ident,
476476
Primitive = $signedness:ident $Int:ident,
477+
SignedPrimitive = $Sint:ty,
477478
UnsignedPrimitive = $Uint:ty,
478479

479480
// Used in doc comments.
@@ -905,6 +906,7 @@ macro_rules! nonzero_integer {
905906

906907
nonzero_integer_signedness_dependent_methods! {
907908
Primitive = $signedness $Int,
909+
SignedPrimitive = $Sint,
908910
UnsignedPrimitive = $Uint,
909911
}
910912

@@ -1128,6 +1130,7 @@ macro_rules! nonzero_integer {
11281130
(
11291131
Self = $Ty:ident,
11301132
Primitive = unsigned $Int:ident,
1133+
SignedPrimitive = $Sint:ident,
11311134
rot = $rot:literal,
11321135
rot_op = $rot_op:literal,
11331136
rot_result = $rot_result:literal,
@@ -1140,6 +1143,7 @@ macro_rules! nonzero_integer {
11401143
#[stable(feature = "nonzero", since = "1.28.0")]
11411144
Self = $Ty,
11421145
Primitive = unsigned $Int,
1146+
SignedPrimitive = $Sint,
11431147
UnsignedPrimitive = $Int,
11441148
rot = $rot,
11451149
rot_op = $rot_op,
@@ -1154,7 +1158,7 @@ macro_rules! nonzero_integer {
11541158
(
11551159
Self = $Ty:ident,
11561160
Primitive = signed $Int:ident,
1157-
UnsignedPrimitive = $UInt:ident,
1161+
UnsignedPrimitive = $Uint:ident,
11581162
rot = $rot:literal,
11591163
rot_op = $rot_op:literal,
11601164
rot_result = $rot_result:literal,
@@ -1166,7 +1170,8 @@ macro_rules! nonzero_integer {
11661170
#[stable(feature = "signed_nonzero", since = "1.34.0")]
11671171
Self = $Ty,
11681172
Primitive = signed $Int,
1169-
UnsignedPrimitive = $UInt,
1173+
SignedPrimitive = $Int,
1174+
UnsignedPrimitive = $Uint,
11701175
rot = $rot,
11711176
rot_op = $rot_op,
11721177
rot_result = $rot_result,
@@ -1286,6 +1291,7 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
12861291
// Associated items for unsigned nonzero types only.
12871292
(
12881293
Primitive = unsigned $Int:ident,
1294+
SignedPrimitive = $Sint:ty,
12891295
UnsignedPrimitive = $Uint:ty,
12901296
) => {
12911297
/// The smallest value that can be represented by this non-zero
@@ -1625,6 +1631,7 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
16251631
// Associated items for signed nonzero types only.
16261632
(
16271633
Primitive = signed $Int:ident,
1634+
SignedPrimitive = $Sint:ty,
16281635
UnsignedPrimitive = $Uint:ty,
16291636
) => {
16301637
/// The smallest value that can be represented by this non-zero
@@ -2041,6 +2048,7 @@ macro_rules! nonzero_integer_signedness_dependent_methods {
20412048
nonzero_integer! {
20422049
Self = NonZeroU8,
20432050
Primitive = unsigned u8,
2051+
SignedPrimitive = i8,
20442052
rot = 2,
20452053
rot_op = "0x82",
20462054
rot_result = "0xa",
@@ -2052,6 +2060,7 @@ nonzero_integer! {
20522060
nonzero_integer! {
20532061
Self = NonZeroU16,
20542062
Primitive = unsigned u16,
2063+
SignedPrimitive = i16,
20552064
rot = 4,
20562065
rot_op = "0xa003",
20572066
rot_result = "0x3a",
@@ -2063,6 +2072,7 @@ nonzero_integer! {
20632072
nonzero_integer! {
20642073
Self = NonZeroU32,
20652074
Primitive = unsigned u32,
2075+
SignedPrimitive = i32,
20662076
rot = 8,
20672077
rot_op = "0x10000b3",
20682078
rot_result = "0xb301",
@@ -2074,6 +2084,7 @@ nonzero_integer! {
20742084
nonzero_integer! {
20752085
Self = NonZeroU64,
20762086
Primitive = unsigned u64,
2087+
SignedPrimitive = i64,
20772088
rot = 12,
20782089
rot_op = "0xaa00000000006e1",
20792090
rot_result = "0x6e10aa",
@@ -2085,6 +2096,7 @@ nonzero_integer! {
20852096
nonzero_integer! {
20862097
Self = NonZeroU128,
20872098
Primitive = unsigned u128,
2099+
SignedPrimitive = i128,
20882100
rot = 16,
20892101
rot_op = "0x13f40000000000000000000000004f76",
20902102
rot_result = "0x4f7613f4",
@@ -2097,6 +2109,7 @@ nonzero_integer! {
20972109
nonzero_integer! {
20982110
Self = NonZeroUsize,
20992111
Primitive = unsigned usize,
2112+
SignedPrimitive = isize,
21002113
rot = 4,
21012114
rot_op = "0xa003",
21022115
rot_result = "0x3a",
@@ -2109,6 +2122,7 @@ nonzero_integer! {
21092122
nonzero_integer! {
21102123
Self = NonZeroUsize,
21112124
Primitive = unsigned usize,
2125+
SignedPrimitive = isize,
21122126
rot = 8,
21132127
rot_op = "0x10000b3",
21142128
rot_result = "0xb301",
@@ -2121,6 +2135,7 @@ nonzero_integer! {
21212135
nonzero_integer! {
21222136
Self = NonZeroUsize,
21232137
Primitive = unsigned usize,
2138+
SignedPrimitive = isize,
21242139
rot = 12,
21252140
rot_op = "0xaa00000000006e1",
21262141
rot_result = "0x6e10aa",

0 commit comments

Comments
 (0)