Skip to content

Commit 3099a79

Browse files
authoredFeb 20, 2024
Rollup merge of #121277 - reitermarkus:generic-nonzero-convert-num, r=dtolnay
Refactor trait implementations in `core::convert::num`. Tracking issue: #120257 Implement conversion traits using generic `NonZero` type, and refactor all macros to use a consistent format/order of parameters. r? `@dtolnay`
·
1.88.01.78.0
2 parents fc5f6f8 + a4d969b commit 3099a79

File tree

1 file changed

+325
-367
lines changed
  • library/core/src/convert

1 file changed

+325
-367
lines changed
 

‎library/core/src/convert/num.rs

Lines changed: 325 additions & 367 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub trait FloatToInt<Int>: private::Sealed + Sized {
1919
}
2020

2121
macro_rules! impl_float_to_int {
22-
( $Float: ident => $( $Int: ident )+ ) => {
22+
($Float:ty => $($Int:ty),+) => {
2323
#[unstable(feature = "convert_float_to_int", issue = "67057")]
2424
impl private::Sealed for $Float {}
2525
$(
@@ -35,14 +35,38 @@ macro_rules! impl_float_to_int {
3535
}
3636
}
3737

38-
impl_float_to_int!(f32 => u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize);
39-
impl_float_to_int!(f64 => u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize);
38+
impl_float_to_int!(f32 => u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
39+
impl_float_to_int!(f64 => u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
4040

4141
// Conversion traits for primitive integer and float types
4242
// Conversions T -> T are covered by a blanket impl and therefore excluded
4343
// Some conversions from and to usize/isize are not implemented due to portability concerns
4444
macro_rules! impl_from {
45-
($Small: ty, $Large: ty, #[$attr:meta], $doc: expr) => {
45+
(bool => $Int:ty $(,)?) => {
46+
impl_from!(
47+
bool => $Int,
48+
#[stable(feature = "from_bool", since = "1.28.0")],
49+
concat!(
50+
"Converts a [`bool`] to [`", stringify!($Int), "`] losslessly.\n",
51+
"The resulting value is `0` for `false` and `1` for `true` values.\n",
52+
"\n",
53+
"# Examples\n",
54+
"\n",
55+
"```\n",
56+
"assert_eq!(", stringify!($Int), "::from(true), 1);\n",
57+
"assert_eq!(", stringify!($Int), "::from(false), 0);\n",
58+
"```\n",
59+
),
60+
);
61+
};
62+
($Small:ty => $Large:ty, #[$attr:meta] $(,)?) => {
63+
impl_from!(
64+
$Small => $Large,
65+
#[$attr],
66+
concat!("Converts [`", stringify!($Small), "`] to [`", stringify!($Large), "`] losslessly."),
67+
);
68+
};
69+
($Small:ty => $Large:ty, #[$attr:meta], $doc:expr $(,)?) => {
4670
#[$attr]
4771
impl From<$Small> for $Large {
4872
// Rustdocs on the impl block show a "[+] show undocumented items" toggle.
@@ -54,91 +78,66 @@ macro_rules! impl_from {
5478
}
5579
}
5680
};
57-
($Small: ty, $Large: ty, #[$attr:meta]) => {
58-
impl_from!($Small,
59-
$Large,
60-
#[$attr],
61-
concat!("Converts `",
62-
stringify!($Small),
63-
"` to `",
64-
stringify!($Large),
65-
"` losslessly."));
66-
}
6781
}
6882

69-
macro_rules! impl_from_bool {
70-
($target: ty, #[$attr:meta]) => {
71-
impl_from!(bool, $target, #[$attr], concat!("Converts a `bool` to a `",
72-
stringify!($target), "`. The resulting value is `0` for `false` and `1` for `true`
73-
values.
74-
75-
# Examples
76-
77-
```
78-
assert_eq!(", stringify!($target), "::from(true), 1);
79-
assert_eq!(", stringify!($target), "::from(false), 0);
80-
```"));
81-
};
82-
}
83-
84-
// Bool -> Any
85-
impl_from_bool! { u8, #[stable(feature = "from_bool", since = "1.28.0")] }
86-
impl_from_bool! { u16, #[stable(feature = "from_bool", since = "1.28.0")] }
87-
impl_from_bool! { u32, #[stable(feature = "from_bool", since = "1.28.0")] }
88-
impl_from_bool! { u64, #[stable(feature = "from_bool", since = "1.28.0")] }
89-
impl_from_bool! { u128, #[stable(feature = "from_bool", since = "1.28.0")] }
90-
impl_from_bool! { usize, #[stable(feature = "from_bool", since = "1.28.0")] }
91-
impl_from_bool! { i8, #[stable(feature = "from_bool", since = "1.28.0")] }
92-
impl_from_bool! { i16, #[stable(feature = "from_bool", since = "1.28.0")] }
93-
impl_from_bool! { i32, #[stable(feature = "from_bool", since = "1.28.0")] }
94-
impl_from_bool! { i64, #[stable(feature = "from_bool", since = "1.28.0")] }
95-
impl_from_bool! { i128, #[stable(feature = "from_bool", since = "1.28.0")] }
96-
impl_from_bool! { isize, #[stable(feature = "from_bool", since = "1.28.0")] }
97-
98-
// Unsigned -> Unsigned
99-
impl_from! { u8, u16, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
100-
impl_from! { u8, u32, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
101-
impl_from! { u8, u64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
102-
impl_from! { u8, u128, #[stable(feature = "i128", since = "1.26.0")] }
103-
impl_from! { u8, usize, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
104-
impl_from! { u16, u32, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
105-
impl_from! { u16, u64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
106-
impl_from! { u16, u128, #[stable(feature = "i128", since = "1.26.0")] }
107-
impl_from! { u32, u64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
108-
impl_from! { u32, u128, #[stable(feature = "i128", since = "1.26.0")] }
109-
impl_from! { u64, u128, #[stable(feature = "i128", since = "1.26.0")] }
110-
111-
// Signed -> Signed
112-
impl_from! { i8, i16, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
113-
impl_from! { i8, i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
114-
impl_from! { i8, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
115-
impl_from! { i8, i128, #[stable(feature = "i128", since = "1.26.0")] }
116-
impl_from! { i8, isize, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
117-
impl_from! { i16, i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
118-
impl_from! { i16, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
119-
impl_from! { i16, i128, #[stable(feature = "i128", since = "1.26.0")] }
120-
impl_from! { i32, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
121-
impl_from! { i32, i128, #[stable(feature = "i128", since = "1.26.0")] }
122-
impl_from! { i64, i128, #[stable(feature = "i128", since = "1.26.0")] }
123-
124-
// Unsigned -> Signed
125-
impl_from! { u8, i16, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
126-
impl_from! { u8, i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
127-
impl_from! { u8, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
128-
impl_from! { u8, i128, #[stable(feature = "i128", since = "1.26.0")] }
129-
impl_from! { u16, i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
130-
impl_from! { u16, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
131-
impl_from! { u16, i128, #[stable(feature = "i128", since = "1.26.0")] }
132-
impl_from! { u32, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")] }
133-
impl_from! { u32, i128, #[stable(feature = "i128", since = "1.26.0")] }
134-
impl_from! { u64, i128, #[stable(feature = "i128", since = "1.26.0")] }
83+
// boolean -> integer
84+
impl_from!(bool => u8);
85+
impl_from!(bool => u16);
86+
impl_from!(bool => u32);
87+
impl_from!(bool => u64);
88+
impl_from!(bool => u128);
89+
impl_from!(bool => usize);
90+
impl_from!(bool => i8);
91+
impl_from!(bool => i16);
92+
impl_from!(bool => i32);
93+
impl_from!(bool => i64);
94+
impl_from!(bool => i128);
95+
impl_from!(bool => isize);
96+
97+
// unsigned integer -> unsigned integer
98+
impl_from!(u8 => u16, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
99+
impl_from!(u8 => u32, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
100+
impl_from!(u8 => u64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
101+
impl_from!(u8 => u128, #[stable(feature = "i128", since = "1.26.0")]);
102+
impl_from!(u8 => usize, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
103+
impl_from!(u16 => u32, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
104+
impl_from!(u16 => u64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
105+
impl_from!(u16 => u128, #[stable(feature = "i128", since = "1.26.0")]);
106+
impl_from!(u32 => u64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
107+
impl_from!(u32 => u128, #[stable(feature = "i128", since = "1.26.0")]);
108+
impl_from!(u64 => u128, #[stable(feature = "i128", since = "1.26.0")]);
109+
110+
// signed integer -> signed integer
111+
impl_from!(i8 => i16, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
112+
impl_from!(i8 => i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
113+
impl_from!(i8 => i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
114+
impl_from!(i8 => i128, #[stable(feature = "i128", since = "1.26.0")]);
115+
impl_from!(i8 => isize, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
116+
impl_from!(i16 => i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
117+
impl_from!(i16 => i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
118+
impl_from!(i16 => i128, #[stable(feature = "i128", since = "1.26.0")]);
119+
impl_from!(i32 => i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
120+
impl_from!(i32 => i128, #[stable(feature = "i128", since = "1.26.0")]);
121+
impl_from!(i64 => i128, #[stable(feature = "i128", since = "1.26.0")]);
122+
123+
// unsigned integer -> signed integer
124+
impl_from!(u8 => i16, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
125+
impl_from!(u8 => i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
126+
impl_from!(u8 => i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
127+
impl_from!(u8 => i128, #[stable(feature = "i128", since = "1.26.0")]);
128+
impl_from!(u16 => i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
129+
impl_from!(u16 => i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
130+
impl_from!(u16 => i128, #[stable(feature = "i128", since = "1.26.0")]);
131+
impl_from!(u32 => i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
132+
impl_from!(u32 => i128, #[stable(feature = "i128", since = "1.26.0")]);
133+
impl_from!(u64 => i128, #[stable(feature = "i128", since = "1.26.0")]);
135134

136135
// The C99 standard defines bounds on INTPTR_MIN, INTPTR_MAX, and UINTPTR_MAX
137136
// which imply that pointer-sized integers must be at least 16 bits:
138137
// https://port70.net/~nsz/c/c99/n1256.html#7.18.2.4
139-
impl_from! { u16, usize, #[stable(feature = "lossless_iusize_conv", since = "1.26.0")] }
140-
impl_from! { u8, isize, #[stable(feature = "lossless_iusize_conv", since = "1.26.0")] }
141-
impl_from! { i16, isize, #[stable(feature = "lossless_iusize_conv", since = "1.26.0")] }
138+
impl_from!(u16 => usize, #[stable(feature = "lossless_iusize_conv", since = "1.26.0")]);
139+
impl_from!(u8 => isize, #[stable(feature = "lossless_iusize_conv", since = "1.26.0")]);
140+
impl_from!(i16 => isize, #[stable(feature = "lossless_iusize_conv", since = "1.26.0")]);
142141

143142
// RISC-V defines the possibility of a 128-bit address space (RV128).
144143

@@ -150,66 +149,54 @@ impl_from! { i16, isize, #[stable(feature = "lossless_iusize_conv", since = "1.2
150149
// they fit in the significand, which is 24 bits in f32 and 53 bits in f64.
151150
// Lossy float conversions are not implemented at this time.
152151

153-
// Signed -> Float
154-
impl_from! { i8, f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")] }
155-
impl_from! { i8, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")] }
156-
impl_from! { i16, f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")] }
157-
impl_from! { i16, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")] }
158-
impl_from! { i32, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")] }
159-
160-
// Unsigned -> Float
161-
impl_from! { u8, f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")] }
162-
impl_from! { u8, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")] }
163-
impl_from! { u16, f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")] }
164-
impl_from! { u16, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")] }
165-
impl_from! { u32, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")] }
166-
167-
// Float -> Float
168-
impl_from! { f32, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")] }
169-
170-
// bool -> Float
171-
#[stable(feature = "float_from_bool", since = "1.68.0")]
172-
impl From<bool> for f32 {
173-
/// Converts `bool` to `f32` losslessly. The resulting value is positive
174-
/// `0.0` for `false` and `1.0` for `true` values.
175-
///
176-
/// # Examples
177-
/// ```
178-
/// let x: f32 = false.into();
179-
/// assert_eq!(x, 0.0);
180-
/// assert!(x.is_sign_positive());
181-
///
182-
/// let y: f32 = true.into();
183-
/// assert_eq!(y, 1.0);
184-
/// ```
185-
#[inline]
186-
fn from(small: bool) -> Self {
187-
small as u8 as Self
188-
}
189-
}
190-
#[stable(feature = "float_from_bool", since = "1.68.0")]
191-
impl From<bool> for f64 {
192-
/// Converts `bool` to `f64` losslessly. The resulting value is positive
193-
/// `0.0` for `false` and `1.0` for `true` values.
194-
///
195-
/// # Examples
196-
/// ```
197-
/// let x: f64 = false.into();
198-
/// assert_eq!(x, 0.0);
199-
/// assert!(x.is_sign_positive());
200-
///
201-
/// let y: f64 = true.into();
202-
/// assert_eq!(y, 1.0);
203-
/// ```
204-
#[inline]
205-
fn from(small: bool) -> Self {
206-
small as u8 as Self
207-
}
152+
// signed integer -> float
153+
impl_from!(i8 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
154+
impl_from!(i8 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
155+
impl_from!(i16 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
156+
impl_from!(i16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
157+
impl_from!(i32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
158+
159+
// unsigned integer -> float
160+
impl_from!(u8 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
161+
impl_from!(u8 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
162+
impl_from!(u16 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
163+
impl_from!(u16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
164+
impl_from!(u32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
165+
166+
// float -> float
167+
impl_from!(f32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
168+
169+
macro_rules! impl_float_from_bool {
170+
($float:ty) => {
171+
#[stable(feature = "float_from_bool", since = "1.68.0")]
172+
impl From<bool> for $float {
173+
#[doc = concat!("Converts a [`bool`] to [`", stringify!($float),"`] losslessly.")]
174+
/// The resulting value is positive `0.0` for `false` and `1.0` for `true` values.
175+
///
176+
/// # Examples
177+
/// ```
178+
#[doc = concat!("let x: ", stringify!($float)," = false.into();")]
179+
/// assert_eq!(x, 0.0);
180+
/// assert!(x.is_sign_positive());
181+
///
182+
#[doc = concat!("let y: ", stringify!($float)," = true.into();")]
183+
/// assert_eq!(y, 1.0);
184+
/// ```
185+
#[inline]
186+
fn from(small: bool) -> Self {
187+
small as u8 as Self
188+
}
189+
}
190+
};
208191
}
209192

193+
// boolean -> float
194+
impl_float_from_bool!(f32);
195+
impl_float_from_bool!(f64);
196+
210197
// no possible bounds violation
211-
macro_rules! try_from_unbounded {
212-
($source:ty, $($target:ty),*) => {$(
198+
macro_rules! impl_try_from_unbounded {
199+
($source:ty => $($target:ty),+) => {$(
213200
#[stable(feature = "try_from", since = "1.34.0")]
214201
impl TryFrom<$source> for $target {
215202
type Error = TryFromIntError;
@@ -226,8 +213,8 @@ macro_rules! try_from_unbounded {
226213
}
227214

228215
// only negative bounds
229-
macro_rules! try_from_lower_bounded {
230-
($source:ty, $($target:ty),*) => {$(
216+
macro_rules! impl_try_from_lower_bounded {
217+
($source:ty => $($target:ty),+) => {$(
231218
#[stable(feature = "try_from", since = "1.34.0")]
232219
impl TryFrom<$source> for $target {
233220
type Error = TryFromIntError;
@@ -248,8 +235,8 @@ macro_rules! try_from_lower_bounded {
248235
}
249236

250237
// unsigned to signed (only positive bound)
251-
macro_rules! try_from_upper_bounded {
252-
($source:ty, $($target:ty),*) => {$(
238+
macro_rules! impl_try_from_upper_bounded {
239+
($source:ty => $($target:ty),+) => {$(
253240
#[stable(feature = "try_from", since = "1.34.0")]
254241
impl TryFrom<$source> for $target {
255242
type Error = TryFromIntError;
@@ -270,8 +257,8 @@ macro_rules! try_from_upper_bounded {
270257
}
271258

272259
// all other cases
273-
macro_rules! try_from_both_bounded {
274-
($source:ty, $($target:ty),*) => {$(
260+
macro_rules! impl_try_from_both_bounded {
261+
($source:ty => $($target:ty),+) => {$(
275262
#[stable(feature = "try_from", since = "1.34.0")]
276263
impl TryFrom<$source> for $target {
277264
type Error = TryFromIntError;
@@ -294,287 +281,258 @@ macro_rules! try_from_both_bounded {
294281
}
295282

296283
macro_rules! rev {
297-
($mac:ident, $source:ty, $($target:ty),*) => {$(
298-
$mac!($target, $source);
284+
($mac:ident, $source:ty => $($target:ty),+) => {$(
285+
$mac!($target => $source);
299286
)*}
300287
}
301288

302-
// intra-sign conversions
303-
try_from_upper_bounded!(u16, u8);
304-
try_from_upper_bounded!(u32, u16, u8);
305-
try_from_upper_bounded!(u64, u32, u16, u8);
306-
try_from_upper_bounded!(u128, u64, u32, u16, u8);
307-
308-
try_from_both_bounded!(i16, i8);
309-
try_from_both_bounded!(i32, i16, i8);
310-
try_from_both_bounded!(i64, i32, i16, i8);
311-
try_from_both_bounded!(i128, i64, i32, i16, i8);
312-
313-
// unsigned-to-signed
314-
try_from_upper_bounded!(u8, i8);
315-
try_from_upper_bounded!(u16, i8, i16);
316-
try_from_upper_bounded!(u32, i8, i16, i32);
317-
try_from_upper_bounded!(u64, i8, i16, i32, i64);
318-
try_from_upper_bounded!(u128, i8, i16, i32, i64, i128);
319-
320-
// signed-to-unsigned
321-
try_from_lower_bounded!(i8, u8, u16, u32, u64, u128);
322-
try_from_lower_bounded!(i16, u16, u32, u64, u128);
323-
try_from_lower_bounded!(i32, u32, u64, u128);
324-
try_from_lower_bounded!(i64, u64, u128);
325-
try_from_lower_bounded!(i128, u128);
326-
try_from_both_bounded!(i16, u8);
327-
try_from_both_bounded!(i32, u16, u8);
328-
try_from_both_bounded!(i64, u32, u16, u8);
329-
try_from_both_bounded!(i128, u64, u32, u16, u8);
289+
// unsigned integer -> unsigned integer
290+
impl_try_from_upper_bounded!(u16 => u8);
291+
impl_try_from_upper_bounded!(u32 => u8, u16);
292+
impl_try_from_upper_bounded!(u64 => u8, u16, u32);
293+
impl_try_from_upper_bounded!(u128 => u8, u16, u32, u64);
294+
295+
// signed integer -> signed integer
296+
impl_try_from_both_bounded!(i16 => i8);
297+
impl_try_from_both_bounded!(i32 => i8, i16);
298+
impl_try_from_both_bounded!(i64 => i8, i16, i32);
299+
impl_try_from_both_bounded!(i128 => i8, i16, i32, i64);
300+
301+
// unsigned integer -> signed integer
302+
impl_try_from_upper_bounded!(u8 => i8);
303+
impl_try_from_upper_bounded!(u16 => i8, i16);
304+
impl_try_from_upper_bounded!(u32 => i8, i16, i32);
305+
impl_try_from_upper_bounded!(u64 => i8, i16, i32, i64);
306+
impl_try_from_upper_bounded!(u128 => i8, i16, i32, i64, i128);
307+
308+
// signed integer -> unsigned integer
309+
impl_try_from_lower_bounded!(i8 => u8, u16, u32, u64, u128);
310+
impl_try_from_both_bounded!(i16 => u8);
311+
impl_try_from_lower_bounded!(i16 => u16, u32, u64, u128);
312+
impl_try_from_both_bounded!(i32 => u8, u16);
313+
impl_try_from_lower_bounded!(i32 => u32, u64, u128);
314+
impl_try_from_both_bounded!(i64 => u8, u16, u32);
315+
impl_try_from_lower_bounded!(i64 => u64, u128);
316+
impl_try_from_both_bounded!(i128 => u8, u16, u32, u64);
317+
impl_try_from_lower_bounded!(i128 => u128);
330318

331319
// usize/isize
332-
try_from_upper_bounded!(usize, isize);
333-
try_from_lower_bounded!(isize, usize);
320+
impl_try_from_upper_bounded!(usize => isize);
321+
impl_try_from_lower_bounded!(isize => usize);
334322

335323
#[cfg(target_pointer_width = "16")]
336324
mod ptr_try_from_impls {
337325
use super::TryFromIntError;
338326
use crate::convert::TryFrom;
339327

340-
try_from_upper_bounded!(usize, u8);
341-
try_from_unbounded!(usize, u16, u32, u64, u128);
342-
try_from_upper_bounded!(usize, i8, i16);
343-
try_from_unbounded!(usize, i32, i64, i128);
328+
impl_try_from_upper_bounded!(usize => u8);
329+
impl_try_from_unbounded!(usize => u16, u32, u64, u128);
330+
impl_try_from_upper_bounded!(usize => i8, i16);
331+
impl_try_from_unbounded!(usize => i32, i64, i128);
344332

345-
try_from_both_bounded!(isize, u8);
346-
try_from_lower_bounded!(isize, u16, u32, u64, u128);
347-
try_from_both_bounded!(isize, i8);
348-
try_from_unbounded!(isize, i16, i32, i64, i128);
333+
impl_try_from_both_bounded!(isize => u8);
334+
impl_try_from_lower_bounded!(isize => u16, u32, u64, u128);
335+
impl_try_from_both_bounded!(isize => i8);
336+
impl_try_from_unbounded!(isize => i16, i32, i64, i128);
349337

350-
rev!(try_from_upper_bounded, usize, u32, u64, u128);
351-
rev!(try_from_lower_bounded, usize, i8, i16);
352-
rev!(try_from_both_bounded, usize, i32, i64, i128);
338+
rev!(impl_try_from_upper_bounded, usize => u32, u64, u128);
339+
rev!(impl_try_from_lower_bounded, usize => i8, i16);
340+
rev!(impl_try_from_both_bounded, usize => i32, i64, i128);
353341

354-
rev!(try_from_upper_bounded, isize, u16, u32, u64, u128);
355-
rev!(try_from_both_bounded, isize, i32, i64, i128);
342+
rev!(impl_try_from_upper_bounded, isize => u16, u32, u64, u128);
343+
rev!(impl_try_from_both_bounded, isize => i32, i64, i128);
356344
}
357345

358346
#[cfg(target_pointer_width = "32")]
359347
mod ptr_try_from_impls {
360348
use super::TryFromIntError;
361349
use crate::convert::TryFrom;
362350

363-
try_from_upper_bounded!(usize, u8, u16);
364-
try_from_unbounded!(usize, u32, u64, u128);
365-
try_from_upper_bounded!(usize, i8, i16, i32);
366-
try_from_unbounded!(usize, i64, i128);
367-
368-
try_from_both_bounded!(isize, u8, u16);
369-
try_from_lower_bounded!(isize, u32, u64, u128);
370-
try_from_both_bounded!(isize, i8, i16);
371-
try_from_unbounded!(isize, i32, i64, i128);
372-
373-
rev!(try_from_unbounded, usize, u32);
374-
rev!(try_from_upper_bounded, usize, u64, u128);
375-
rev!(try_from_lower_bounded, usize, i8, i16, i32);
376-
rev!(try_from_both_bounded, usize, i64, i128);
377-
378-
rev!(try_from_unbounded, isize, u16);
379-
rev!(try_from_upper_bounded, isize, u32, u64, u128);
380-
rev!(try_from_unbounded, isize, i32);
381-
rev!(try_from_both_bounded, isize, i64, i128);
351+
impl_try_from_upper_bounded!(usize => u8, u16);
352+
impl_try_from_unbounded!(usize => u32, u64, u128);
353+
impl_try_from_upper_bounded!(usize => i8, i16, i32);
354+
impl_try_from_unbounded!(usize => i64, i128);
355+
356+
impl_try_from_both_bounded!(isize => u8, u16);
357+
impl_try_from_lower_bounded!(isize => u32, u64, u128);
358+
impl_try_from_both_bounded!(isize => i8, i16);
359+
impl_try_from_unbounded!(isize => i32, i64, i128);
360+
361+
rev!(impl_try_from_unbounded, usize => u32);
362+
rev!(impl_try_from_upper_bounded, usize => u64, u128);
363+
rev!(impl_try_from_lower_bounded, usize => i8, i16, i32);
364+
rev!(impl_try_from_both_bounded, usize => i64, i128);
365+
366+
rev!(impl_try_from_unbounded, isize => u16);
367+
rev!(impl_try_from_upper_bounded, isize => u32, u64, u128);
368+
rev!(impl_try_from_unbounded, isize => i32);
369+
rev!(impl_try_from_both_bounded, isize => i64, i128);
382370
}
383371

384372
#[cfg(target_pointer_width = "64")]
385373
mod ptr_try_from_impls {
386374
use super::TryFromIntError;
387375
use crate::convert::TryFrom;
388376

389-
try_from_upper_bounded!(usize, u8, u16, u32);
390-
try_from_unbounded!(usize, u64, u128);
391-
try_from_upper_bounded!(usize, i8, i16, i32, i64);
392-
try_from_unbounded!(usize, i128);
393-
394-
try_from_both_bounded!(isize, u8, u16, u32);
395-
try_from_lower_bounded!(isize, u64, u128);
396-
try_from_both_bounded!(isize, i8, i16, i32);
397-
try_from_unbounded!(isize, i64, i128);
398-
399-
rev!(try_from_unbounded, usize, u32, u64);
400-
rev!(try_from_upper_bounded, usize, u128);
401-
rev!(try_from_lower_bounded, usize, i8, i16, i32, i64);
402-
rev!(try_from_both_bounded, usize, i128);
403-
404-
rev!(try_from_unbounded, isize, u16, u32);
405-
rev!(try_from_upper_bounded, isize, u64, u128);
406-
rev!(try_from_unbounded, isize, i32, i64);
407-
rev!(try_from_both_bounded, isize, i128);
377+
impl_try_from_upper_bounded!(usize => u8, u16, u32);
378+
impl_try_from_unbounded!(usize => u64, u128);
379+
impl_try_from_upper_bounded!(usize => i8, i16, i32, i64);
380+
impl_try_from_unbounded!(usize => i128);
381+
382+
impl_try_from_both_bounded!(isize => u8, u16, u32);
383+
impl_try_from_lower_bounded!(isize => u64, u128);
384+
impl_try_from_both_bounded!(isize => i8, i16, i32);
385+
impl_try_from_unbounded!(isize => i64, i128);
386+
387+
rev!(impl_try_from_unbounded, usize => u32, u64);
388+
rev!(impl_try_from_upper_bounded, usize => u128);
389+
rev!(impl_try_from_lower_bounded, usize => i8, i16, i32, i64);
390+
rev!(impl_try_from_both_bounded, usize => i128);
391+
392+
rev!(impl_try_from_unbounded, isize => u16, u32);
393+
rev!(impl_try_from_upper_bounded, isize => u64, u128);
394+
rev!(impl_try_from_unbounded, isize => i32, i64);
395+
rev!(impl_try_from_both_bounded, isize => i128);
408396
}
409397

410398
// Conversion traits for non-zero integer types
411-
use crate::num::NonZeroI128;
412-
use crate::num::NonZeroI16;
413-
use crate::num::NonZeroI32;
414-
use crate::num::NonZeroI64;
415-
use crate::num::NonZeroI8;
416-
use crate::num::NonZeroIsize;
417-
use crate::num::NonZeroU128;
418-
use crate::num::NonZeroU16;
419-
use crate::num::NonZeroU32;
420-
use crate::num::NonZeroU64;
421-
use crate::num::NonZeroU8;
422-
use crate::num::NonZeroUsize;
423-
424-
macro_rules! nzint_impl_from {
425-
($Small: ty, $Large: ty, #[$attr:meta], $doc: expr) => {
426-
#[$attr]
427-
impl From<$Small> for $Large {
399+
use crate::num::NonZero;
400+
401+
macro_rules! impl_nonzero_int_from_nonzero_int {
402+
($Small:ty => $Large:ty) => {
403+
#[stable(feature = "nz_int_conv", since = "1.41.0")]
404+
impl From<NonZero<$Small>> for NonZero<$Large> {
428405
// Rustdocs on the impl block show a "[+] show undocumented items" toggle.
429406
// Rustdocs on functions do not.
430-
#[doc = $doc]
407+
#[doc = concat!("Converts <code>[NonZero]\\<[", stringify!($Small), "]></code> ")]
408+
#[doc = concat!("to <code>[NonZero]\\<[", stringify!($Large), "]></code> losslessly.")]
431409
#[inline]
432-
fn from(small: $Small) -> Self {
410+
fn from(small: NonZero<$Small>) -> Self {
433411
// SAFETY: input type guarantees the value is non-zero
434-
unsafe {
435-
Self::new_unchecked(From::from(small.get()))
436-
}
412+
unsafe { Self::new_unchecked(From::from(small.get())) }
437413
}
438414
}
439415
};
440-
($Small: ty, $Large: ty, #[$attr:meta]) => {
441-
nzint_impl_from!($Small,
442-
$Large,
443-
#[$attr],
444-
concat!("Converts `",
445-
stringify!($Small),
446-
"` to `",
447-
stringify!($Large),
448-
"` losslessly."));
449-
}
450416
}
451417

452-
// Non-zero Unsigned -> Non-zero Unsigned
453-
nzint_impl_from! { NonZeroU8, NonZeroU16, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
454-
nzint_impl_from! { NonZeroU8, NonZeroU32, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
455-
nzint_impl_from! { NonZeroU8, NonZeroU64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
456-
nzint_impl_from! { NonZeroU8, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
457-
nzint_impl_from! { NonZeroU8, NonZeroUsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
458-
nzint_impl_from! { NonZeroU16, NonZeroU32, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
459-
nzint_impl_from! { NonZeroU16, NonZeroU64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
460-
nzint_impl_from! { NonZeroU16, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
461-
nzint_impl_from! { NonZeroU16, NonZeroUsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
462-
nzint_impl_from! { NonZeroU32, NonZeroU64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
463-
nzint_impl_from! { NonZeroU32, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
464-
nzint_impl_from! { NonZeroU64, NonZeroU128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
465-
466-
// Non-zero Signed -> Non-zero Signed
467-
nzint_impl_from! { NonZeroI8, NonZeroI16, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
468-
nzint_impl_from! { NonZeroI8, NonZeroI32, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
469-
nzint_impl_from! { NonZeroI8, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
470-
nzint_impl_from! { NonZeroI8, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
471-
nzint_impl_from! { NonZeroI8, NonZeroIsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
472-
nzint_impl_from! { NonZeroI16, NonZeroI32, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
473-
nzint_impl_from! { NonZeroI16, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
474-
nzint_impl_from! { NonZeroI16, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
475-
nzint_impl_from! { NonZeroI16, NonZeroIsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
476-
nzint_impl_from! { NonZeroI32, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
477-
nzint_impl_from! { NonZeroI32, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
478-
nzint_impl_from! { NonZeroI64, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
479-
480-
// NonZero UnSigned -> Non-zero Signed
481-
nzint_impl_from! { NonZeroU8, NonZeroI16, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
482-
nzint_impl_from! { NonZeroU8, NonZeroI32, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
483-
nzint_impl_from! { NonZeroU8, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
484-
nzint_impl_from! { NonZeroU8, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
485-
nzint_impl_from! { NonZeroU8, NonZeroIsize, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
486-
nzint_impl_from! { NonZeroU16, NonZeroI32, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
487-
nzint_impl_from! { NonZeroU16, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
488-
nzint_impl_from! { NonZeroU16, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
489-
nzint_impl_from! { NonZeroU32, NonZeroI64, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
490-
nzint_impl_from! { NonZeroU32, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
491-
nzint_impl_from! { NonZeroU64, NonZeroI128, #[stable(feature = "nz_int_conv", since = "1.41.0")] }
492-
493-
macro_rules! nzint_impl_try_from_int {
494-
($Int: ty, $NonZeroInt: ty, #[$attr:meta], $doc: expr) => {
495-
#[$attr]
496-
impl TryFrom<$Int> for $NonZeroInt {
418+
// non-zero unsigned integer -> non-zero unsigned integer
419+
impl_nonzero_int_from_nonzero_int!(u8 => u16);
420+
impl_nonzero_int_from_nonzero_int!(u8 => u32);
421+
impl_nonzero_int_from_nonzero_int!(u8 => u64);
422+
impl_nonzero_int_from_nonzero_int!(u8 => u128);
423+
impl_nonzero_int_from_nonzero_int!(u8 => usize);
424+
impl_nonzero_int_from_nonzero_int!(u16 => u32);
425+
impl_nonzero_int_from_nonzero_int!(u16 => u64);
426+
impl_nonzero_int_from_nonzero_int!(u16 => u128);
427+
impl_nonzero_int_from_nonzero_int!(u16 => usize);
428+
impl_nonzero_int_from_nonzero_int!(u32 => u64);
429+
impl_nonzero_int_from_nonzero_int!(u32 => u128);
430+
impl_nonzero_int_from_nonzero_int!(u64 => u128);
431+
432+
// non-zero signed integer -> non-zero signed integer
433+
impl_nonzero_int_from_nonzero_int!(i8 => i16);
434+
impl_nonzero_int_from_nonzero_int!(i8 => i32);
435+
impl_nonzero_int_from_nonzero_int!(i8 => i64);
436+
impl_nonzero_int_from_nonzero_int!(i8 => i128);
437+
impl_nonzero_int_from_nonzero_int!(i8 => isize);
438+
impl_nonzero_int_from_nonzero_int!(i16 => i32);
439+
impl_nonzero_int_from_nonzero_int!(i16 => i64);
440+
impl_nonzero_int_from_nonzero_int!(i16 => i128);
441+
impl_nonzero_int_from_nonzero_int!(i16 => isize);
442+
impl_nonzero_int_from_nonzero_int!(i32 => i64);
443+
impl_nonzero_int_from_nonzero_int!(i32 => i128);
444+
impl_nonzero_int_from_nonzero_int!(i64 => i128);
445+
446+
// non-zero unsigned -> non-zero signed integer
447+
impl_nonzero_int_from_nonzero_int!(u8 => i16);
448+
impl_nonzero_int_from_nonzero_int!(u8 => i32);
449+
impl_nonzero_int_from_nonzero_int!(u8 => i64);
450+
impl_nonzero_int_from_nonzero_int!(u8 => i128);
451+
impl_nonzero_int_from_nonzero_int!(u8 => isize);
452+
impl_nonzero_int_from_nonzero_int!(u16 => i32);
453+
impl_nonzero_int_from_nonzero_int!(u16 => i64);
454+
impl_nonzero_int_from_nonzero_int!(u16 => i128);
455+
impl_nonzero_int_from_nonzero_int!(u32 => i64);
456+
impl_nonzero_int_from_nonzero_int!(u32 => i128);
457+
impl_nonzero_int_from_nonzero_int!(u64 => i128);
458+
459+
macro_rules! impl_nonzero_int_try_from_int {
460+
($Int:ty) => {
461+
#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
462+
impl TryFrom<$Int> for NonZero<$Int> {
497463
type Error = TryFromIntError;
498464

499465
// Rustdocs on the impl block show a "[+] show undocumented items" toggle.
500466
// Rustdocs on functions do not.
501-
#[doc = $doc]
467+
#[doc = concat!("Attempts to convert [`", stringify!($Int), "`] ")]
468+
#[doc = concat!("to <code>[NonZero]\\<[", stringify!($Int), "]></code>.")]
502469
#[inline]
503470
fn try_from(value: $Int) -> Result<Self, Self::Error> {
504471
Self::new(value).ok_or(TryFromIntError(()))
505472
}
506473
}
507474
};
508-
($Int: ty, $NonZeroInt: ty, #[$attr:meta]) => {
509-
nzint_impl_try_from_int!($Int,
510-
$NonZeroInt,
511-
#[$attr],
512-
concat!("Attempts to convert `",
513-
stringify!($Int),
514-
"` to `",
515-
stringify!($NonZeroInt),
516-
"`."));
517-
}
518475
}
519476

520-
// Int -> Non-zero Int
521-
nzint_impl_try_from_int! { u8, NonZeroU8, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] }
522-
nzint_impl_try_from_int! { u16, NonZeroU16, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] }
523-
nzint_impl_try_from_int! { u32, NonZeroU32, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] }
524-
nzint_impl_try_from_int! { u64, NonZeroU64, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] }
525-
nzint_impl_try_from_int! { u128, NonZeroU128, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] }
526-
nzint_impl_try_from_int! { usize, NonZeroUsize, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] }
527-
nzint_impl_try_from_int! { i8, NonZeroI8, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] }
528-
nzint_impl_try_from_int! { i16, NonZeroI16, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] }
529-
nzint_impl_try_from_int! { i32, NonZeroI32, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] }
530-
nzint_impl_try_from_int! { i64, NonZeroI64, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] }
531-
nzint_impl_try_from_int! { i128, NonZeroI128, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] }
532-
nzint_impl_try_from_int! { isize, NonZeroIsize, #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")] }
533-
534-
macro_rules! nzint_impl_try_from_nzint {
535-
($From:ty => $To:ty, $doc: expr) => {
477+
// integer -> non-zero integer
478+
impl_nonzero_int_try_from_int!(u8);
479+
impl_nonzero_int_try_from_int!(u16);
480+
impl_nonzero_int_try_from_int!(u32);
481+
impl_nonzero_int_try_from_int!(u64);
482+
impl_nonzero_int_try_from_int!(u128);
483+
impl_nonzero_int_try_from_int!(usize);
484+
impl_nonzero_int_try_from_int!(i8);
485+
impl_nonzero_int_try_from_int!(i16);
486+
impl_nonzero_int_try_from_int!(i32);
487+
impl_nonzero_int_try_from_int!(i64);
488+
impl_nonzero_int_try_from_int!(i128);
489+
impl_nonzero_int_try_from_int!(isize);
490+
491+
macro_rules! impl_nonzero_int_try_from_nonzero_int {
492+
($source:ty => $($target:ty),+) => {$(
536493
#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
537-
impl TryFrom<$From> for $To {
494+
impl TryFrom<NonZero<$source>> for NonZero<$target> {
538495
type Error = TryFromIntError;
539496

540497
// Rustdocs on the impl block show a "[+] show undocumented items" toggle.
541498
// Rustdocs on functions do not.
542-
#[doc = $doc]
499+
#[doc = concat!("Attempts to convert <code>[NonZero]\\<[", stringify!($source), "]></code> ")]
500+
#[doc = concat!("to <code>[NonZero]\\<[", stringify!($target), "]></code>.")]
543501
#[inline]
544-
fn try_from(value: $From) -> Result<Self, Self::Error> {
545-
TryFrom::try_from(value.get()).map(|v| {
546-
// SAFETY: $From is a NonZero type, so v is not zero.
547-
unsafe { Self::new_unchecked(v) }
548-
})
502+
fn try_from(value: NonZero<$source>) -> Result<Self, Self::Error> {
503+
// SAFETY: Input is guaranteed to be non-zero.
504+
Ok(unsafe { Self::new_unchecked(<$target>::try_from(value.get())?) })
549505
}
550506
}
551-
};
552-
($To:ty: $($From: ty),*) => {$(
553-
nzint_impl_try_from_nzint!(
554-
$From => $To,
555-
concat!(
556-
"Attempts to convert `",
557-
stringify!($From),
558-
"` to `",
559-
stringify!($To),
560-
"`.",
561-
)
562-
);
563507
)*};
564508
}
565509

566-
// Non-zero int -> non-zero unsigned int
567-
nzint_impl_try_from_nzint! { NonZeroU8: NonZeroI8, NonZeroU16, NonZeroI16, NonZeroU32, NonZeroI32, NonZeroU64, NonZeroI64, NonZeroU128, NonZeroI128, NonZeroUsize, NonZeroIsize }
568-
nzint_impl_try_from_nzint! { NonZeroU16: NonZeroI8, NonZeroI16, NonZeroU32, NonZeroI32, NonZeroU64, NonZeroI64, NonZeroU128, NonZeroI128, NonZeroUsize, NonZeroIsize }
569-
nzint_impl_try_from_nzint! { NonZeroU32: NonZeroI8, NonZeroI16, NonZeroI32, NonZeroU64, NonZeroI64, NonZeroU128, NonZeroI128, NonZeroUsize, NonZeroIsize }
570-
nzint_impl_try_from_nzint! { NonZeroU64: NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroU128, NonZeroI128, NonZeroUsize, NonZeroIsize }
571-
nzint_impl_try_from_nzint! { NonZeroU128: NonZeroI8, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI128, NonZeroUsize, NonZeroIsize }
572-
nzint_impl_try_from_nzint! { NonZeroUsize: NonZeroI8, NonZeroI16, NonZeroU32, NonZeroI32, NonZeroU64, NonZeroI64, NonZeroU128, NonZeroI128, NonZeroIsize }
573-
574-
// Non-zero int -> non-zero signed int
575-
nzint_impl_try_from_nzint! { NonZeroI8: NonZeroU8, NonZeroU16, NonZeroI16, NonZeroU32, NonZeroI32, NonZeroU64, NonZeroI64, NonZeroU128, NonZeroI128, NonZeroUsize, NonZeroIsize }
576-
nzint_impl_try_from_nzint! { NonZeroI16: NonZeroU16, NonZeroU32, NonZeroI32, NonZeroU64, NonZeroI64, NonZeroU128, NonZeroI128, NonZeroUsize, NonZeroIsize }
577-
nzint_impl_try_from_nzint! { NonZeroI32: NonZeroU32, NonZeroU64, NonZeroI64, NonZeroU128, NonZeroI128, NonZeroUsize, NonZeroIsize }
578-
nzint_impl_try_from_nzint! { NonZeroI64: NonZeroU64, NonZeroU128, NonZeroI128, NonZeroUsize, NonZeroIsize }
579-
nzint_impl_try_from_nzint! { NonZeroI128: NonZeroU128, NonZeroUsize, NonZeroIsize }
580-
nzint_impl_try_from_nzint! { NonZeroIsize: NonZeroU16, NonZeroU32, NonZeroI32, NonZeroU64, NonZeroI64, NonZeroU128, NonZeroI128, NonZeroUsize }
510+
// unsigned non-zero integer -> unsigned non-zero integer
511+
impl_nonzero_int_try_from_nonzero_int!(u16 => u8);
512+
impl_nonzero_int_try_from_nonzero_int!(u32 => u8, u16, usize);
513+
impl_nonzero_int_try_from_nonzero_int!(u64 => u8, u16, u32, usize);
514+
impl_nonzero_int_try_from_nonzero_int!(u128 => u8, u16, u32, u64, usize);
515+
impl_nonzero_int_try_from_nonzero_int!(usize => u8, u16, u32, u64, u128);
516+
517+
// signed non-zero integer -> signed non-zero integer
518+
impl_nonzero_int_try_from_nonzero_int!(i16 => i8);
519+
impl_nonzero_int_try_from_nonzero_int!(i32 => i8, i16, isize);
520+
impl_nonzero_int_try_from_nonzero_int!(i64 => i8, i16, i32, isize);
521+
impl_nonzero_int_try_from_nonzero_int!(i128 => i8, i16, i32, i64, isize);
522+
impl_nonzero_int_try_from_nonzero_int!(isize => i8, i16, i32, i64, i128);
523+
524+
// unsigned non-zero integer -> signed non-zero integer
525+
impl_nonzero_int_try_from_nonzero_int!(u8 => i8);
526+
impl_nonzero_int_try_from_nonzero_int!(u16 => i8, i16, isize);
527+
impl_nonzero_int_try_from_nonzero_int!(u32 => i8, i16, i32, isize);
528+
impl_nonzero_int_try_from_nonzero_int!(u64 => i8, i16, i32, i64, isize);
529+
impl_nonzero_int_try_from_nonzero_int!(u128 => i8, i16, i32, i64, i128, isize);
530+
impl_nonzero_int_try_from_nonzero_int!(usize => i8, i16, i32, i64, i128, isize);
531+
532+
// signed non-zero integer -> unsigned non-zero integer
533+
impl_nonzero_int_try_from_nonzero_int!(i8 => u8, u16, u32, u64, u128, usize);
534+
impl_nonzero_int_try_from_nonzero_int!(i16 => u8, u16, u32, u64, u128, usize);
535+
impl_nonzero_int_try_from_nonzero_int!(i32 => u8, u16, u32, u64, u128, usize);
536+
impl_nonzero_int_try_from_nonzero_int!(i64 => u8, u16, u32, u64, u128, usize);
537+
impl_nonzero_int_try_from_nonzero_int!(i128 => u8, u16, u32, u64, u128, usize);
538+
impl_nonzero_int_try_from_nonzero_int!(isize => u8, u16, u32, u64, u128, usize);

0 commit comments

Comments
 (0)
Please sign in to comment.