Skip to main content

core/convert/
num.rs

1use crate::num::{IntErrorKind, TryFromIntError};
2
3mod private {
4    /// This trait being unreachable from outside the crate
5    /// prevents other implementations of the `FloatToInt` trait,
6    /// which allows potentially adding more trait methods after the trait is `#[stable]`.
7    #[unstable(feature = "convert_float_to_int", issue = "67057")]
8    pub trait Sealed {}
9}
10
11/// Supporting trait for inherent methods of `f32` and `f64` such as `to_int_unchecked`.
12/// Typically doesn’t need to be used directly.
13#[unstable(feature = "convert_float_to_int", issue = "67057")]
14pub trait FloatToInt<Int>: private::Sealed + Sized {
15    #[unstable(feature = "convert_float_to_int", issue = "67057")]
16    #[doc(hidden)]
17    unsafe fn to_int_unchecked(self) -> Int;
18}
19
20macro_rules! impl_float_to_int {
21    ($Float:ty => $($Int:ty),+) => {
22        #[unstable(feature = "convert_float_to_int", issue = "67057")]
23        impl private::Sealed for $Float {}
24        $(
25            #[unstable(feature = "convert_float_to_int", issue = "67057")]
26            impl FloatToInt<$Int> for $Float {
27                #[inline]
28                unsafe fn to_int_unchecked(self) -> $Int {
29                    // SAFETY: the safety contract must be upheld by the caller.
30                    unsafe { crate::intrinsics::float_to_int_unchecked(self) }
31                }
32            }
33        )+
34    }
35}
36
37#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl private::Sealed for f16 { }
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u8> for f16 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u8 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u16> for f16 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u16 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u32> for f16 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u32 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u64> for f16 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u64 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u128> for f16 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u128 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<usize> for f16 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> usize {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i8> for f16 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i8 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i16> for f16 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i16 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i32> for f16 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i32 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i64> for f16 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i64 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i128> for f16 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i128 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<isize> for f16 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> isize {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}impl_float_to_int!(f16 => u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
38#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl private::Sealed for f32 { }
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u8> for f32 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u8 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u16> for f32 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u16 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u32> for f32 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u32 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u64> for f32 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u64 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u128> for f32 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u128 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<usize> for f32 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> usize {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i8> for f32 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i8 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i16> for f32 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i16 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i32> for f32 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i32 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i64> for f32 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i64 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i128> for f32 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i128 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<isize> for f32 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> isize {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}impl_float_to_int!(f32 => u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
39#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl private::Sealed for f64 { }
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u8> for f64 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u8 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u16> for f64 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u16 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u32> for f64 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u32 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u64> for f64 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u64 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u128> for f64 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u128 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<usize> for f64 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> usize {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i8> for f64 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i8 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i16> for f64 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i16 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i32> for f64 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i32 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i64> for f64 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i64 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i128> for f64 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i128 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<isize> for f64 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> isize {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}impl_float_to_int!(f64 => u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
40#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl private::Sealed for f128 { }
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u8> for f128 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u8 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u16> for f128 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u16 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u32> for f128 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u32 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u64> for f128 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u64 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<u128> for f128 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> u128 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<usize> for f128 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> usize {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i8> for f128 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i8 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i16> for f128 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i16 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i32> for f128 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i32 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i64> for f128 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i64 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<i128> for f128 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> i128 {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}
#[unstable(feature = "convert_float_to_int", issue = "67057")]
impl FloatToInt<isize> for f128 {
    #[inline]
    unsafe fn to_int_unchecked(self) -> isize {
        unsafe { crate::intrinsics::float_to_int_unchecked(self) }
    }
}impl_float_to_int!(f128 => u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
41
42/// Implement `From<bool>` for integers
43macro_rules! impl_from_bool {
44    ($($int:ty)*) => {$(
45        #[stable(feature = "from_bool", since = "1.28.0")]
46        #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
47        impl const From<bool> for $int {
48            /// Converts from [`bool`] to
49            #[doc = concat!("[`", stringify!($int), "`]")]
50            /// , by turning `false` into `0` and `true` into `1`.
51            ///
52            /// # Examples
53            ///
54            /// ```
55            #[doc = concat!("assert_eq!(", stringify!($int), "::from(false), 0);")]
56            ///
57            #[doc = concat!("assert_eq!(", stringify!($int), "::from(true), 1);")]
58            /// ```
59            #[inline(always)]
60            fn from(b: bool) -> Self {
61                b as Self
62            }
63        }
64    )*}
65}
66
67// boolean -> integer
68#[stable(feature = "from_bool", since = "1.28.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<bool> for usize {
    /// Converts from [`bool`] to
    #[doc = "[`usize`]"]
    /// , by turning `false` into `0` and `true` into `1`.
    ///
    /// # Examples
    ///
    /// ```
    #[doc = "assert_eq!(usize::from(false), 0);"]
    ///
    #[doc = "assert_eq!(usize::from(true), 1);"]
    /// ```
    #[inline(always)]
    fn from(b: bool) -> Self { b as Self }
}impl_from_bool!(u8 u16 u32 u64 u128 usize);
69#[stable(feature = "from_bool", since = "1.28.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<bool> for isize {
    /// Converts from [`bool`] to
    #[doc = "[`isize`]"]
    /// , by turning `false` into `0` and `true` into `1`.
    ///
    /// # Examples
    ///
    /// ```
    #[doc = "assert_eq!(isize::from(false), 0);"]
    ///
    #[doc = "assert_eq!(isize::from(true), 1);"]
    /// ```
    #[inline(always)]
    fn from(b: bool) -> Self { b as Self }
}impl_from_bool!(i8 i16 i32 i64 i128 isize);
70
71/// Implement `From<$small>` for `$large`
72macro_rules! impl_from {
73    ($small:ty => $large:ty, $(#[$attrs:meta]),+) => {
74        $(#[$attrs])+
75        #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
76        impl const From<$small> for $large {
77            #[doc = concat!("Converts from [`", stringify!($small), "`] to [`", stringify!($large), "`] losslessly.")]
78            #[inline(always)]
79            fn from(small: $small) -> Self {
80                debug_assert!(<$large>::MIN as i128 <= <$small>::MIN as i128);
81                debug_assert!(<$small>::MAX as u128 <= <$large>::MAX as u128);
82                small as Self
83            }
84        }
85    }
86}
87
88// unsigned integer -> unsigned integer
89#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for u16 {
    #[doc = "Converts from [`u8`] to [`u16`] losslessly."]
    #[inline(always)]
    fn from(small: u8) -> Self {
        if true {
            if !(<u16>::MIN as i128 <= <u8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <u16>::MIN as i128 <= <u8>::MIN as i128")
            };
        };
        if true {
            if !(<u8>::MAX as u128 <= <u16>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <u16>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u8 => u16, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
90#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for u32 {
    #[doc = "Converts from [`u8`] to [`u32`] losslessly."]
    #[inline(always)]
    fn from(small: u8) -> Self {
        if true {
            if !(<u32>::MIN as i128 <= <u8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <u32>::MIN as i128 <= <u8>::MIN as i128")
            };
        };
        if true {
            if !(<u8>::MAX as u128 <= <u32>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <u32>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u8 => u32, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
91#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for u64 {
    #[doc = "Converts from [`u8`] to [`u64`] losslessly."]
    #[inline(always)]
    fn from(small: u8) -> Self {
        if true {
            if !(<u64>::MIN as i128 <= <u8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <u64>::MIN as i128 <= <u8>::MIN as i128")
            };
        };
        if true {
            if !(<u8>::MAX as u128 <= <u64>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <u64>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u8 => u64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
92#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for u128 {
    #[doc = "Converts from [`u8`] to [`u128`] losslessly."]
    #[inline(always)]
    fn from(small: u8) -> Self {
        if true {
            if !(<u128>::MIN as i128 <= <u8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <u128>::MIN as i128 <= <u8>::MIN as i128")
            };
        };
        if true {
            if !(<u8>::MAX as u128 <= <u128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <u128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u8 => u128, #[stable(feature = "i128", since = "1.26.0")]);
93#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for usize {
    #[doc = "Converts from [`u8`] to [`usize`] losslessly."]
    #[inline(always)]
    fn from(small: u8) -> Self {
        if true {
            if !(<usize>::MIN as i128 <= <u8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <usize>::MIN as i128 <= <u8>::MIN as i128")
            };
        };
        if true {
            if !(<u8>::MAX as u128 <= <usize>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <usize>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u8 => usize, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
94#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for u32 {
    #[doc = "Converts from [`u16`] to [`u32`] losslessly."]
    #[inline(always)]
    fn from(small: u16) -> Self {
        if true {
            if !(<u32>::MIN as i128 <= <u16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <u32>::MIN as i128 <= <u16>::MIN as i128")
            };
        };
        if true {
            if !(<u16>::MAX as u128 <= <u32>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <u32>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u16 => u32, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
95#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for u64 {
    #[doc = "Converts from [`u16`] to [`u64`] losslessly."]
    #[inline(always)]
    fn from(small: u16) -> Self {
        if true {
            if !(<u64>::MIN as i128 <= <u16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <u64>::MIN as i128 <= <u16>::MIN as i128")
            };
        };
        if true {
            if !(<u16>::MAX as u128 <= <u64>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <u64>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u16 => u64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
96#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for u128 {
    #[doc = "Converts from [`u16`] to [`u128`] losslessly."]
    #[inline(always)]
    fn from(small: u16) -> Self {
        if true {
            if !(<u128>::MIN as i128 <= <u16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <u128>::MIN as i128 <= <u16>::MIN as i128")
            };
        };
        if true {
            if !(<u16>::MAX as u128 <= <u128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <u128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u16 => u128, #[stable(feature = "i128", since = "1.26.0")]);
97#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u32> for u64 {
    #[doc = "Converts from [`u32`] to [`u64`] losslessly."]
    #[inline(always)]
    fn from(small: u32) -> Self {
        if true {
            if !(<u64>::MIN as i128 <= <u32>::MIN as i128) {
                crate::panicking::panic("assertion failed: <u64>::MIN as i128 <= <u32>::MIN as i128")
            };
        };
        if true {
            if !(<u32>::MAX as u128 <= <u64>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u32>::MAX as u128 <= <u64>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u32 => u64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
98#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u32> for u128 {
    #[doc = "Converts from [`u32`] to [`u128`] losslessly."]
    #[inline(always)]
    fn from(small: u32) -> Self {
        if true {
            if !(<u128>::MIN as i128 <= <u32>::MIN as i128) {
                crate::panicking::panic("assertion failed: <u128>::MIN as i128 <= <u32>::MIN as i128")
            };
        };
        if true {
            if !(<u32>::MAX as u128 <= <u128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u32>::MAX as u128 <= <u128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u32 => u128, #[stable(feature = "i128", since = "1.26.0")]);
99#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u64> for u128 {
    #[doc = "Converts from [`u64`] to [`u128`] losslessly."]
    #[inline(always)]
    fn from(small: u64) -> Self {
        if true {
            if !(<u128>::MIN as i128 <= <u64>::MIN as i128) {
                crate::panicking::panic("assertion failed: <u128>::MIN as i128 <= <u64>::MIN as i128")
            };
        };
        if true {
            if !(<u64>::MAX as u128 <= <u128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u64>::MAX as u128 <= <u128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u64 => u128, #[stable(feature = "i128", since = "1.26.0")]);
100
101// signed integer -> signed integer
102#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i8> for i16 {
    #[doc = "Converts from [`i8`] to [`i16`] losslessly."]
    #[inline(always)]
    fn from(small: i8) -> Self {
        if true {
            if !(<i16>::MIN as i128 <= <i8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i16>::MIN as i128 <= <i8>::MIN as i128")
            };
        };
        if true {
            if !(<i8>::MAX as u128 <= <i16>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i8>::MAX as u128 <= <i16>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i8 => i16, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
103#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i8> for i32 {
    #[doc = "Converts from [`i8`] to [`i32`] losslessly."]
    #[inline(always)]
    fn from(small: i8) -> Self {
        if true {
            if !(<i32>::MIN as i128 <= <i8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i32>::MIN as i128 <= <i8>::MIN as i128")
            };
        };
        if true {
            if !(<i8>::MAX as u128 <= <i32>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i8>::MAX as u128 <= <i32>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i8 => i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
104#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i8> for i64 {
    #[doc = "Converts from [`i8`] to [`i64`] losslessly."]
    #[inline(always)]
    fn from(small: i8) -> Self {
        if true {
            if !(<i64>::MIN as i128 <= <i8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i64>::MIN as i128 <= <i8>::MIN as i128")
            };
        };
        if true {
            if !(<i8>::MAX as u128 <= <i64>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i8>::MAX as u128 <= <i64>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i8 => i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
105#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i8> for i128 {
    #[doc = "Converts from [`i8`] to [`i128`] losslessly."]
    #[inline(always)]
    fn from(small: i8) -> Self {
        if true {
            if !(<i128>::MIN as i128 <= <i8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i128>::MIN as i128 <= <i8>::MIN as i128")
            };
        };
        if true {
            if !(<i8>::MAX as u128 <= <i128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i8>::MAX as u128 <= <i128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i8 => i128, #[stable(feature = "i128", since = "1.26.0")]);
106#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i8> for isize {
    #[doc = "Converts from [`i8`] to [`isize`] losslessly."]
    #[inline(always)]
    fn from(small: i8) -> Self {
        if true {
            if !(<isize>::MIN as i128 <= <i8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <isize>::MIN as i128 <= <i8>::MIN as i128")
            };
        };
        if true {
            if !(<i8>::MAX as u128 <= <isize>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i8>::MAX as u128 <= <isize>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i8 => isize, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
107#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i16> for i32 {
    #[doc = "Converts from [`i16`] to [`i32`] losslessly."]
    #[inline(always)]
    fn from(small: i16) -> Self {
        if true {
            if !(<i32>::MIN as i128 <= <i16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i32>::MIN as i128 <= <i16>::MIN as i128")
            };
        };
        if true {
            if !(<i16>::MAX as u128 <= <i32>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i16>::MAX as u128 <= <i32>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i16 => i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
108#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i16> for i64 {
    #[doc = "Converts from [`i16`] to [`i64`] losslessly."]
    #[inline(always)]
    fn from(small: i16) -> Self {
        if true {
            if !(<i64>::MIN as i128 <= <i16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i64>::MIN as i128 <= <i16>::MIN as i128")
            };
        };
        if true {
            if !(<i16>::MAX as u128 <= <i64>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i16>::MAX as u128 <= <i64>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i16 => i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
109#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i16> for i128 {
    #[doc = "Converts from [`i16`] to [`i128`] losslessly."]
    #[inline(always)]
    fn from(small: i16) -> Self {
        if true {
            if !(<i128>::MIN as i128 <= <i16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i128>::MIN as i128 <= <i16>::MIN as i128")
            };
        };
        if true {
            if !(<i16>::MAX as u128 <= <i128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i16>::MAX as u128 <= <i128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i16 => i128, #[stable(feature = "i128", since = "1.26.0")]);
110#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i32> for i64 {
    #[doc = "Converts from [`i32`] to [`i64`] losslessly."]
    #[inline(always)]
    fn from(small: i32) -> Self {
        if true {
            if !(<i64>::MIN as i128 <= <i32>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i64>::MIN as i128 <= <i32>::MIN as i128")
            };
        };
        if true {
            if !(<i32>::MAX as u128 <= <i64>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i32>::MAX as u128 <= <i64>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i32 => i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
111#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i32> for i128 {
    #[doc = "Converts from [`i32`] to [`i128`] losslessly."]
    #[inline(always)]
    fn from(small: i32) -> Self {
        if true {
            if !(<i128>::MIN as i128 <= <i32>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i128>::MIN as i128 <= <i32>::MIN as i128")
            };
        };
        if true {
            if !(<i32>::MAX as u128 <= <i128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i32>::MAX as u128 <= <i128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i32 => i128, #[stable(feature = "i128", since = "1.26.0")]);
112#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i64> for i128 {
    #[doc = "Converts from [`i64`] to [`i128`] losslessly."]
    #[inline(always)]
    fn from(small: i64) -> Self {
        if true {
            if !(<i128>::MIN as i128 <= <i64>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i128>::MIN as i128 <= <i64>::MIN as i128")
            };
        };
        if true {
            if !(<i64>::MAX as u128 <= <i128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i64>::MAX as u128 <= <i128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i64 => i128, #[stable(feature = "i128", since = "1.26.0")]);
113
114// unsigned integer -> signed integer
115#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for i16 {
    #[doc = "Converts from [`u8`] to [`i16`] losslessly."]
    #[inline(always)]
    fn from(small: u8) -> Self {
        if true {
            if !(<i16>::MIN as i128 <= <u8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i16>::MIN as i128 <= <u8>::MIN as i128")
            };
        };
        if true {
            if !(<u8>::MAX as u128 <= <i16>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <i16>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u8 => i16, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
116#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for i32 {
    #[doc = "Converts from [`u8`] to [`i32`] losslessly."]
    #[inline(always)]
    fn from(small: u8) -> Self {
        if true {
            if !(<i32>::MIN as i128 <= <u8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i32>::MIN as i128 <= <u8>::MIN as i128")
            };
        };
        if true {
            if !(<u8>::MAX as u128 <= <i32>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <i32>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u8 => i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
117#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for i64 {
    #[doc = "Converts from [`u8`] to [`i64`] losslessly."]
    #[inline(always)]
    fn from(small: u8) -> Self {
        if true {
            if !(<i64>::MIN as i128 <= <u8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i64>::MIN as i128 <= <u8>::MIN as i128")
            };
        };
        if true {
            if !(<u8>::MAX as u128 <= <i64>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <i64>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u8 => i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
118#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for i128 {
    #[doc = "Converts from [`u8`] to [`i128`] losslessly."]
    #[inline(always)]
    fn from(small: u8) -> Self {
        if true {
            if !(<i128>::MIN as i128 <= <u8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i128>::MIN as i128 <= <u8>::MIN as i128")
            };
        };
        if true {
            if !(<u8>::MAX as u128 <= <i128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <i128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u8 => i128, #[stable(feature = "i128", since = "1.26.0")]);
119#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for i32 {
    #[doc = "Converts from [`u16`] to [`i32`] losslessly."]
    #[inline(always)]
    fn from(small: u16) -> Self {
        if true {
            if !(<i32>::MIN as i128 <= <u16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i32>::MIN as i128 <= <u16>::MIN as i128")
            };
        };
        if true {
            if !(<u16>::MAX as u128 <= <i32>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <i32>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u16 => i32, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
120#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for i64 {
    #[doc = "Converts from [`u16`] to [`i64`] losslessly."]
    #[inline(always)]
    fn from(small: u16) -> Self {
        if true {
            if !(<i64>::MIN as i128 <= <u16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i64>::MIN as i128 <= <u16>::MIN as i128")
            };
        };
        if true {
            if !(<u16>::MAX as u128 <= <i64>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <i64>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u16 => i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
121#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for i128 {
    #[doc = "Converts from [`u16`] to [`i128`] losslessly."]
    #[inline(always)]
    fn from(small: u16) -> Self {
        if true {
            if !(<i128>::MIN as i128 <= <u16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i128>::MIN as i128 <= <u16>::MIN as i128")
            };
        };
        if true {
            if !(<u16>::MAX as u128 <= <i128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <i128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u16 => i128, #[stable(feature = "i128", since = "1.26.0")]);
122#[stable(feature = "lossless_int_conv", since = "1.5.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u32> for i64 {
    #[doc = "Converts from [`u32`] to [`i64`] losslessly."]
    #[inline(always)]
    fn from(small: u32) -> Self {
        if true {
            if !(<i64>::MIN as i128 <= <u32>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i64>::MIN as i128 <= <u32>::MIN as i128")
            };
        };
        if true {
            if !(<u32>::MAX as u128 <= <i64>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u32>::MAX as u128 <= <i64>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u32 => i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]);
123#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u32> for i128 {
    #[doc = "Converts from [`u32`] to [`i128`] losslessly."]
    #[inline(always)]
    fn from(small: u32) -> Self {
        if true {
            if !(<i128>::MIN as i128 <= <u32>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i128>::MIN as i128 <= <u32>::MIN as i128")
            };
        };
        if true {
            if !(<u32>::MAX as u128 <= <i128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u32>::MAX as u128 <= <i128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u32 => i128, #[stable(feature = "i128", since = "1.26.0")]);
124#[stable(feature = "i128", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u64> for i128 {
    #[doc = "Converts from [`u64`] to [`i128`] losslessly."]
    #[inline(always)]
    fn from(small: u64) -> Self {
        if true {
            if !(<i128>::MIN as i128 <= <u64>::MIN as i128) {
                crate::panicking::panic("assertion failed: <i128>::MIN as i128 <= <u64>::MIN as i128")
            };
        };
        if true {
            if !(<u64>::MAX as u128 <= <i128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u64>::MAX as u128 <= <i128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u64 => i128, #[stable(feature = "i128", since = "1.26.0")]);
125
126// The C99 standard defines bounds on INTPTR_MIN, INTPTR_MAX, and UINTPTR_MAX
127// which imply that pointer-sized integers must be at least 16 bits:
128// https://port70.net/~nsz/c/c99/n1256.html#7.18.2.4
129#[stable(feature = "lossless_iusize_conv", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for usize {
    #[doc = "Converts from [`u16`] to [`usize`] losslessly."]
    #[inline(always)]
    fn from(small: u16) -> Self {
        if true {
            if !(<usize>::MIN as i128 <= <u16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <usize>::MIN as i128 <= <u16>::MIN as i128")
            };
        };
        if true {
            if !(<u16>::MAX as u128 <= <usize>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <usize>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u16 => usize, #[stable(feature = "lossless_iusize_conv", since = "1.26.0")]);
130#[stable(feature = "lossless_iusize_conv", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for isize {
    #[doc = "Converts from [`u8`] to [`isize`] losslessly."]
    #[inline(always)]
    fn from(small: u8) -> Self {
        if true {
            if !(<isize>::MIN as i128 <= <u8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <isize>::MIN as i128 <= <u8>::MIN as i128")
            };
        };
        if true {
            if !(<u8>::MAX as u128 <= <isize>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <isize>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u8 => isize, #[stable(feature = "lossless_iusize_conv", since = "1.26.0")]);
131#[stable(feature = "lossless_iusize_conv", since = "1.26.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i16> for isize {
    #[doc = "Converts from [`i16`] to [`isize`] losslessly."]
    #[inline(always)]
    fn from(small: i16) -> Self {
        if true {
            if !(<isize>::MIN as i128 <= <i16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <isize>::MIN as i128 <= <i16>::MIN as i128")
            };
        };
        if true {
            if !(<i16>::MAX as u128 <= <isize>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i16>::MAX as u128 <= <isize>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i16 => isize, #[stable(feature = "lossless_iusize_conv", since = "1.26.0")]);
132
133// RISC-V defines the possibility of a 128-bit address space (RV128).
134
135// CHERI proposes 128-bit “capabilities”. Unclear if this would be relevant to usize/isize.
136// https://www.cl.cam.ac.uk/research/security/ctsrd/pdfs/20171017a-cheri-poster.pdf
137// https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-951.pdf
138
139// Note: integers can only be represented with full precision in a float if
140// they fit in the significand, which is:
141// * 11 bits in f16
142// * 24 bits in f32
143// * 53 bits in f64
144// * 113 bits in f128
145// Lossy float conversions are not implemented at this time.
146// FIXME(f16,f128): The `f16`/`f128` impls `#[stable]` attributes should be changed to reference
147// `f16`/`f128` when they are stabilised (trait impls have to have a `#[stable]` attribute, but none
148// of the `f16`/`f128` impls can be used on stable as the `f16` and `f128` types are unstable).
149
150// signed integer -> float
151#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i8> for f16 {
    #[doc = "Converts from [`i8`] to [`f16`] losslessly."]
    #[inline(always)]
    fn from(small: i8) -> Self {
        if true {
            if !(<f16>::MIN as i128 <= <i8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f16>::MIN as i128 <= <i8>::MIN as i128")
            };
        };
        if true {
            if !(<i8>::MAX as u128 <= <f16>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i8>::MAX as u128 <= <f16>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i8 => f16, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
152#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i8> for f32 {
    #[doc = "Converts from [`i8`] to [`f32`] losslessly."]
    #[inline(always)]
    fn from(small: i8) -> Self {
        if true {
            if !(<f32>::MIN as i128 <= <i8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f32>::MIN as i128 <= <i8>::MIN as i128")
            };
        };
        if true {
            if !(<i8>::MAX as u128 <= <f32>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i8>::MAX as u128 <= <f32>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i8 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
153#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i8> for f64 {
    #[doc = "Converts from [`i8`] to [`f64`] losslessly."]
    #[inline(always)]
    fn from(small: i8) -> Self {
        if true {
            if !(<f64>::MIN as i128 <= <i8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f64>::MIN as i128 <= <i8>::MIN as i128")
            };
        };
        if true {
            if !(<i8>::MAX as u128 <= <f64>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i8>::MAX as u128 <= <f64>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i8 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
154#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i8> for f128 {
    #[doc = "Converts from [`i8`] to [`f128`] losslessly."]
    #[inline(always)]
    fn from(small: i8) -> Self {
        if true {
            if !(<f128>::MIN as i128 <= <i8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <i8>::MIN as i128")
            };
        };
        if true {
            if !(<i8>::MAX as u128 <= <f128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i8>::MAX as u128 <= <f128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i8 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
155#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i16> for f32 {
    #[doc = "Converts from [`i16`] to [`f32`] losslessly."]
    #[inline(always)]
    fn from(small: i16) -> Self {
        if true {
            if !(<f32>::MIN as i128 <= <i16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f32>::MIN as i128 <= <i16>::MIN as i128")
            };
        };
        if true {
            if !(<i16>::MAX as u128 <= <f32>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i16>::MAX as u128 <= <f32>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i16 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
156#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i16> for f64 {
    #[doc = "Converts from [`i16`] to [`f64`] losslessly."]
    #[inline(always)]
    fn from(small: i16) -> Self {
        if true {
            if !(<f64>::MIN as i128 <= <i16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f64>::MIN as i128 <= <i16>::MIN as i128")
            };
        };
        if true {
            if !(<i16>::MAX as u128 <= <f64>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i16>::MAX as u128 <= <f64>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
157#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i16> for f128 {
    #[doc = "Converts from [`i16`] to [`f128`] losslessly."]
    #[inline(always)]
    fn from(small: i16) -> Self {
        if true {
            if !(<f128>::MIN as i128 <= <i16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <i16>::MIN as i128")
            };
        };
        if true {
            if !(<i16>::MAX as u128 <= <f128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i16>::MAX as u128 <= <f128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i16 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
158#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i32> for f64 {
    #[doc = "Converts from [`i32`] to [`f64`] losslessly."]
    #[inline(always)]
    fn from(small: i32) -> Self {
        if true {
            if !(<f64>::MIN as i128 <= <i32>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f64>::MIN as i128 <= <i32>::MIN as i128")
            };
        };
        if true {
            if !(<i32>::MAX as u128 <= <f64>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i32>::MAX as u128 <= <f64>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
159#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i32> for f128 {
    #[doc = "Converts from [`i32`] to [`f128`] losslessly."]
    #[inline(always)]
    fn from(small: i32) -> Self {
        if true {
            if !(<f128>::MIN as i128 <= <i32>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <i32>::MIN as i128")
            };
        };
        if true {
            if !(<i32>::MAX as u128 <= <f128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i32>::MAX as u128 <= <f128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i32 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
160#[unstable(feature = "f128", issue = "116909")]
#[unstable_feature_bound(f128)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<i64> for f128 {
    #[doc = "Converts from [`i64`] to [`f128`] losslessly."]
    #[inline(always)]
    fn from(small: i64) -> Self {
        if true {
            if !(<f128>::MIN as i128 <= <i64>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <i64>::MIN as i128")
            };
        };
        if true {
            if !(<i64>::MAX as u128 <= <f128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <i64>::MAX as u128 <= <f128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(i64 => f128, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f128)]);
161
162// unsigned integer -> float
163#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for f16 {
    #[doc = "Converts from [`u8`] to [`f16`] losslessly."]
    #[inline(always)]
    fn from(small: u8) -> Self {
        if true {
            if !(<f16>::MIN as i128 <= <u8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f16>::MIN as i128 <= <u8>::MIN as i128")
            };
        };
        if true {
            if !(<u8>::MAX as u128 <= <f16>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <f16>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u8 => f16, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
164#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for f32 {
    #[doc = "Converts from [`u8`] to [`f32`] losslessly."]
    #[inline(always)]
    fn from(small: u8) -> Self {
        if true {
            if !(<f32>::MIN as i128 <= <u8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f32>::MIN as i128 <= <u8>::MIN as i128")
            };
        };
        if true {
            if !(<u8>::MAX as u128 <= <f32>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <f32>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u8 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
165#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for f64 {
    #[doc = "Converts from [`u8`] to [`f64`] losslessly."]
    #[inline(always)]
    fn from(small: u8) -> Self {
        if true {
            if !(<f64>::MIN as i128 <= <u8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f64>::MIN as i128 <= <u8>::MIN as i128")
            };
        };
        if true {
            if !(<u8>::MAX as u128 <= <f64>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <f64>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u8 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
166#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u8> for f128 {
    #[doc = "Converts from [`u8`] to [`f128`] losslessly."]
    #[inline(always)]
    fn from(small: u8) -> Self {
        if true {
            if !(<f128>::MIN as i128 <= <u8>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <u8>::MIN as i128")
            };
        };
        if true {
            if !(<u8>::MAX as u128 <= <f128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u8>::MAX as u128 <= <f128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u8 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
167#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for f32 {
    #[doc = "Converts from [`u16`] to [`f32`] losslessly."]
    #[inline(always)]
    fn from(small: u16) -> Self {
        if true {
            if !(<f32>::MIN as i128 <= <u16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f32>::MIN as i128 <= <u16>::MIN as i128")
            };
        };
        if true {
            if !(<u16>::MAX as u128 <= <f32>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <f32>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u16 => f32, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
168#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for f64 {
    #[doc = "Converts from [`u16`] to [`f64`] losslessly."]
    #[inline(always)]
    fn from(small: u16) -> Self {
        if true {
            if !(<f64>::MIN as i128 <= <u16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f64>::MIN as i128 <= <u16>::MIN as i128")
            };
        };
        if true {
            if !(<u16>::MAX as u128 <= <f64>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <f64>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
169#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u16> for f128 {
    #[doc = "Converts from [`u16`] to [`f128`] losslessly."]
    #[inline(always)]
    fn from(small: u16) -> Self {
        if true {
            if !(<f128>::MIN as i128 <= <u16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <u16>::MIN as i128")
            };
        };
        if true {
            if !(<u16>::MAX as u128 <= <f128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u16>::MAX as u128 <= <f128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u16 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
170#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u32> for f64 {
    #[doc = "Converts from [`u32`] to [`f64`] losslessly."]
    #[inline(always)]
    fn from(small: u32) -> Self {
        if true {
            if !(<f64>::MIN as i128 <= <u32>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f64>::MIN as i128 <= <u32>::MIN as i128")
            };
        };
        if true {
            if !(<u32>::MAX as u128 <= <f64>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u32>::MAX as u128 <= <f64>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
171#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u32> for f128 {
    #[doc = "Converts from [`u32`] to [`f128`] losslessly."]
    #[inline(always)]
    fn from(small: u32) -> Self {
        if true {
            if !(<f128>::MIN as i128 <= <u32>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <u32>::MIN as i128")
            };
        };
        if true {
            if !(<u32>::MAX as u128 <= <f128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u32>::MAX as u128 <= <f128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u32 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
172#[unstable(feature = "f128", issue = "116909")]
#[unstable_feature_bound(f128)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<u64> for f128 {
    #[doc = "Converts from [`u64`] to [`f128`] losslessly."]
    #[inline(always)]
    fn from(small: u64) -> Self {
        if true {
            if !(<f128>::MIN as i128 <= <u64>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <u64>::MIN as i128")
            };
        };
        if true {
            if !(<u64>::MAX as u128 <= <f128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <u64>::MAX as u128 <= <f128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(u64 => f128, #[unstable(feature = "f128", issue = "116909")], #[unstable_feature_bound(f128)]);
173
174// float -> float
175
176// FIXME(f16): adding the additional `From<{float}>` impl to `f32` would break inference in cases
177// like `f32::from(1.0)`. The type checker has a custom workaround to keep that and similar code
178// compiling even with the second `From<16> for f32` instance. We keep this instance unstable for
179// now so that we can later remove the workaround.
180//
181// See also <https://github.com/rust-lang/rust/issues/123831>.
182#[unstable(feature = "f32_from_f16", issue = "154005")]
#[unstable_feature_bound(f32_from_f16)]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<f16> for f32 {
    #[doc = "Converts from [`f16`] to [`f32`] losslessly."]
    #[inline(always)]
    fn from(small: f16) -> Self {
        if true {
            if !(<f32>::MIN as i128 <= <f16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f32>::MIN as i128 <= <f16>::MIN as i128")
            };
        };
        if true {
            if !(<f16>::MAX as u128 <= <f32>::MAX as u128) {
                crate::panicking::panic("assertion failed: <f16>::MAX as u128 <= <f32>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(f16 => f32, #[unstable(feature = "f32_from_f16", issue = "154005")], #[unstable_feature_bound(f32_from_f16)]);
183#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<f16> for f64 {
    #[doc = "Converts from [`f16`] to [`f64`] losslessly."]
    #[inline(always)]
    fn from(small: f16) -> Self {
        if true {
            if !(<f64>::MIN as i128 <= <f16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f64>::MIN as i128 <= <f16>::MIN as i128")
            };
        };
        if true {
            if !(<f16>::MAX as u128 <= <f64>::MAX as u128) {
                crate::panicking::panic("assertion failed: <f16>::MAX as u128 <= <f64>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(f16 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
184#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<f16> for f128 {
    #[doc = "Converts from [`f16`] to [`f128`] losslessly."]
    #[inline(always)]
    fn from(small: f16) -> Self {
        if true {
            if !(<f128>::MIN as i128 <= <f16>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <f16>::MIN as i128")
            };
        };
        if true {
            if !(<f16>::MAX as u128 <= <f128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <f16>::MAX as u128 <= <f128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(f16 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
185#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<f32> for f64 {
    #[doc = "Converts from [`f32`] to [`f64`] losslessly."]
    #[inline(always)]
    fn from(small: f32) -> Self {
        if true {
            if !(<f64>::MIN as i128 <= <f32>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f64>::MIN as i128 <= <f32>::MIN as i128")
            };
        };
        if true {
            if !(<f32>::MAX as u128 <= <f64>::MAX as u128) {
                crate::panicking::panic("assertion failed: <f32>::MAX as u128 <= <f64>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(f32 => f64, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
186#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<f32> for f128 {
    #[doc = "Converts from [`f32`] to [`f128`] losslessly."]
    #[inline(always)]
    fn from(small: f32) -> Self {
        if true {
            if !(<f128>::MIN as i128 <= <f32>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <f32>::MIN as i128")
            };
        };
        if true {
            if !(<f32>::MAX as u128 <= <f128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <f32>::MAX as u128 <= <f128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(f32 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
187#[stable(feature = "lossless_float_conv", since = "1.6.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<f64> for f128 {
    #[doc = "Converts from [`f64`] to [`f128`] losslessly."]
    #[inline(always)]
    fn from(small: f64) -> Self {
        if true {
            if !(<f128>::MIN as i128 <= <f64>::MIN as i128) {
                crate::panicking::panic("assertion failed: <f128>::MIN as i128 <= <f64>::MIN as i128")
            };
        };
        if true {
            if !(<f64>::MAX as u128 <= <f128>::MAX as u128) {
                crate::panicking::panic("assertion failed: <f64>::MAX as u128 <= <f128>::MAX as u128")
            };
        };
        small as Self
    }
}impl_from!(f64 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
188
189macro_rules! impl_float_from_bool {
190    (
191        $float:ty $(;
192            doctest_prefix: $(#[doc = $doctest_prefix:literal])*
193            doctest_suffix: $(#[doc = $doctest_suffix:literal])*
194        )?
195    ) => {
196        #[stable(feature = "float_from_bool", since = "1.68.0")]
197        #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
198            impl const From<bool> for $float {
199            #[doc = concat!("Converts a [`bool`] to [`", stringify!($float),"`] losslessly.")]
200            /// The resulting value is positive `0.0` for `false` and `1.0` for `true` values.
201            ///
202            /// # Examples
203            /// ```
204            $($(#[doc = $doctest_prefix])*)?
205            #[doc = concat!("let x = ", stringify!($float), "::from(false);")]
206            /// assert_eq!(x, 0.0);
207            /// assert!(x.is_sign_positive());
208            ///
209            #[doc = concat!("let y = ", stringify!($float), "::from(true);")]
210            /// assert_eq!(y, 1.0);
211            $($(#[doc = $doctest_suffix])*)?
212            /// ```
213            #[inline]
214            fn from(small: bool) -> Self {
215                small as u8 as Self
216            }
217        }
218    };
219}
220
221// boolean -> float
222#[stable(feature = "float_from_bool", since = "1.68.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<bool> for f16 {
    #[doc = "Converts a [`bool`] to [`f16`] losslessly."]
    /// The resulting value is positive `0.0` for `false` and `1.0` for `true` values.
    ///
    /// # Examples
    /// ```
    #[doc = r"# #![allow(unused_features)]"]
    #[doc = r"#![feature(f16)]"]
    #[doc = r#"# #[cfg(all(target_arch = "x86_64", target_os = "linux"))] {"#]
    #[doc = r""]
    #[doc = "let x = f16::from(false);"]
    /// assert_eq!(x, 0.0);
    /// assert!(x.is_sign_positive());
    ///
    #[doc = "let y = f16::from(true);"]
    /// assert_eq!(y, 1.0);
    #[doc = r"# }"]
    /// ```
    #[inline]
    fn from(small: bool) -> Self { small as u8 as Self }
}impl_float_from_bool!(
223    f16;
224    doctest_prefix:
225    // rustdoc doesn't remove the conventional space after the `///`
226    ///# #![allow(unused_features)]
227    ///#![feature(f16)]
228    ///# #[cfg(all(target_arch = "x86_64", target_os = "linux"))] {
229    ///
230    doctest_suffix:
231    ///# }
232);
233#[stable(feature = "float_from_bool", since = "1.68.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<bool> for f32 {
    #[doc = "Converts a [`bool`] to [`f32`] losslessly."]
    /// The resulting value is positive `0.0` for `false` and `1.0` for `true` values.
    ///
    /// # Examples
    /// ```
    #[doc = "let x = f32::from(false);"]
    /// assert_eq!(x, 0.0);
    /// assert!(x.is_sign_positive());
    ///
    #[doc = "let y = f32::from(true);"]
    /// assert_eq!(y, 1.0);
    /// ```
    #[inline]
    fn from(small: bool) -> Self { small as u8 as Self }
}impl_float_from_bool!(f32);
234#[stable(feature = "float_from_bool", since = "1.68.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<bool> for f64 {
    #[doc = "Converts a [`bool`] to [`f64`] losslessly."]
    /// The resulting value is positive `0.0` for `false` and `1.0` for `true` values.
    ///
    /// # Examples
    /// ```
    #[doc = "let x = f64::from(false);"]
    /// assert_eq!(x, 0.0);
    /// assert!(x.is_sign_positive());
    ///
    #[doc = "let y = f64::from(true);"]
    /// assert_eq!(y, 1.0);
    /// ```
    #[inline]
    fn from(small: bool) -> Self { small as u8 as Self }
}impl_float_from_bool!(f64);
235#[stable(feature = "float_from_bool", since = "1.68.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<bool> for f128 {
    #[doc = "Converts a [`bool`] to [`f128`] losslessly."]
    /// The resulting value is positive `0.0` for `false` and `1.0` for `true` values.
    ///
    /// # Examples
    /// ```
    #[doc = r"# #![allow(unused_features)]"]
    #[doc = r"#![feature(f128)]"]
    #[doc = r#"# #[cfg(all(target_arch = "x86_64", target_os = "linux"))] {"#]
    #[doc = r""]
    #[doc = "let x = f128::from(false);"]
    /// assert_eq!(x, 0.0);
    /// assert!(x.is_sign_positive());
    ///
    #[doc = "let y = f128::from(true);"]
    /// assert_eq!(y, 1.0);
    #[doc = r"# }"]
    /// ```
    #[inline]
    fn from(small: bool) -> Self { small as u8 as Self }
}impl_float_from_bool!(
236    f128;
237    doctest_prefix:
238    ///# #![allow(unused_features)]
239    ///#![feature(f128)]
240    ///# #[cfg(all(target_arch = "x86_64", target_os = "linux"))] {
241    ///
242    doctest_suffix:
243    ///# }
244);
245
246// no possible bounds violation
247macro_rules! impl_try_from_unbounded {
248    ($source:ty => $($target:ty),+) => {$(
249        #[stable(feature = "try_from", since = "1.34.0")]
250        #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
251        impl const TryFrom<$source> for $target {
252            type Error = TryFromIntError;
253
254            /// Tries to create the target number type from a source
255            /// number type. This returns an error if the source value
256            /// is outside of the range of the target type.
257            #[inline]
258            fn try_from(value: $source) -> Result<Self, Self::Error> {
259                Ok(value as Self)
260            }
261        }
262    )*}
263}
264
265// only negative bounds
266macro_rules! impl_try_from_lower_bounded {
267    ($source:ty => $($target:ty),+) => {$(
268        #[stable(feature = "try_from", since = "1.34.0")]
269        #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
270        impl const TryFrom<$source> for $target {
271            type Error = TryFromIntError;
272
273            /// Tries to create the target number type from a source
274            /// number type. This returns an error if the source value
275            /// is outside of the range of the target type.
276            #[inline]
277            fn try_from(u: $source) -> Result<Self, Self::Error> {
278                if u >= 0 {
279                    Ok(u as Self)
280                } else {
281                    Err(TryFromIntError(IntErrorKind::NegOverflow))
282                }
283            }
284        }
285    )*}
286}
287
288// unsigned to signed (only positive bound)
289macro_rules! impl_try_from_upper_bounded {
290    ($source:ty => $($target:ty),+) => {$(
291        #[stable(feature = "try_from", since = "1.34.0")]
292        #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
293        impl const TryFrom<$source> for $target {
294            type Error = TryFromIntError;
295
296            /// Tries to create the target number type from a source
297            /// number type. This returns an error if the source value
298            /// is outside of the range of the target type.
299            #[inline]
300            fn try_from(u: $source) -> Result<Self, Self::Error> {
301                if u > (Self::MAX as $source) {
302                    Err(TryFromIntError(IntErrorKind::PosOverflow))
303                } else {
304                    Ok(u as Self)
305                }
306            }
307        }
308    )*}
309}
310
311// all other cases
312macro_rules! impl_try_from_both_bounded {
313    ($source:ty => $($target:ty),+) => {$(
314        #[stable(feature = "try_from", since = "1.34.0")]
315        #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
316        impl const TryFrom<$source> for $target {
317            type Error = TryFromIntError;
318
319            /// Tries to create the target number type from a source
320            /// number type. This returns an error if the source value
321            /// is outside of the range of the target type.
322            #[inline]
323            fn try_from(u: $source) -> Result<Self, Self::Error> {
324                let min = Self::MIN as $source;
325                let max = Self::MAX as $source;
326                if u < min {
327                    Err(TryFromIntError(IntErrorKind::NegOverflow))
328                } else if u > max {
329                    Err(TryFromIntError(IntErrorKind::PosOverflow))
330                } else {
331                    Ok(u as Self)
332                }
333            }
334        }
335    )*}
336}
337
338/// Implement `TryFrom<integer>` for `bool`
339macro_rules! impl_try_from_integer_for_bool {
340    ($signedness:ident $($int:ty)+) => {$(
341        #[stable(feature = "bool_try_from_int", since = "1.95.0")]
342        #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
343        impl const TryFrom<$int> for bool {
344            type Error = TryFromIntError;
345
346            /// Tries to create a bool from an integer type.
347            /// Returns an error if the integer is not 0 or 1.
348            ///
349            /// # Examples
350            ///
351            /// ```
352            #[doc = concat!("assert_eq!(bool::try_from(0_", stringify!($int), "), Ok(false));")]
353            ///
354            #[doc = concat!("assert_eq!(bool::try_from(1_", stringify!($int), "), Ok(true));")]
355            ///
356            #[doc = concat!("assert!(bool::try_from(2_", stringify!($int), ").is_err());")]
357            /// ```
358            #[inline]
359            fn try_from(i: $int) -> Result<Self, Self::Error> {
360                sign_dependent_expr!{
361                    $signedness ?
362                    if signed {
363                        match i {
364                            0 => Ok(false),
365                            1 => Ok(true),
366                            ..0 => Err(TryFromIntError(IntErrorKind::NegOverflow)),
367                            2.. => Err(TryFromIntError(IntErrorKind::PosOverflow)),
368                        }
369                    }
370                    if unsigned {
371                        match i {
372                            0 => Ok(false),
373                            1 => Ok(true),
374                            2.. => Err(TryFromIntError(IntErrorKind::PosOverflow)),
375                        }
376                    }
377                }
378            }
379        }
380    )*}
381}
382
383macro_rules! rev {
384    ($mac:ident, $source:ty => $($target:ty),+) => {$(
385        $mac!($target => $source);
386    )*}
387}
388
389// integer -> bool
390#[stable(feature = "bool_try_from_int", since = "1.95.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u8> for bool {
    type Error = TryFromIntError;
    /// Tries to create a bool from an integer type.
    /// Returns an error if the integer is not 0 or 1.
    ///
    /// # Examples
    ///
    /// ```
    #[doc = "assert_eq!(bool::try_from(0_u8), Ok(false));"]
    ///
    #[doc = "assert_eq!(bool::try_from(1_u8), Ok(true));"]
    ///
    #[doc = "assert!(bool::try_from(2_u8).is_err());"]
    /// ```
    #[inline]
    fn try_from(i: u8) -> Result<Self, Self::Error> {
        match i {
            0 => Ok(false),
            1 => Ok(true),
            2.. => Err(TryFromIntError(IntErrorKind::PosOverflow)),
        }
    }
}impl_try_from_integer_for_bool!(unsigned u128 u64 u32 u16 u8);
391#[stable(feature = "bool_try_from_int", since = "1.95.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i8> for bool {
    type Error = TryFromIntError;
    /// Tries to create a bool from an integer type.
    /// Returns an error if the integer is not 0 or 1.
    ///
    /// # Examples
    ///
    /// ```
    #[doc = "assert_eq!(bool::try_from(0_i8), Ok(false));"]
    ///
    #[doc = "assert_eq!(bool::try_from(1_i8), Ok(true));"]
    ///
    #[doc = "assert!(bool::try_from(2_i8).is_err());"]
    /// ```
    #[inline]
    fn try_from(i: i8) -> Result<Self, Self::Error> {
        match i {
            0 => Ok(false),
            1 => Ok(true),
            ..0 => Err(TryFromIntError(IntErrorKind::NegOverflow)),
            2.. => Err(TryFromIntError(IntErrorKind::PosOverflow)),
        }
    }
}impl_try_from_integer_for_bool!(signed i128 i64 i32 i16 i8);
392
393// unsigned integer -> unsigned integer
394#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u16> for u8 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: u16) -> Result<Self, Self::Error> {
        if u > (Self::MAX as u16) {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_upper_bounded!(u16 => u8);
395#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u32> for u16 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: u32) -> Result<Self, Self::Error> {
        if u > (Self::MAX as u32) {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_upper_bounded!(u32 => u8, u16);
396#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u64> for u32 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: u64) -> Result<Self, Self::Error> {
        if u > (Self::MAX as u64) {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_upper_bounded!(u64 => u8, u16, u32);
397#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u128> for u64 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: u128) -> Result<Self, Self::Error> {
        if u > (Self::MAX as u128) {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_upper_bounded!(u128 => u8, u16, u32, u64);
398
399// signed integer -> signed integer
400#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i16> for i8 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: i16) -> Result<Self, Self::Error> {
        let min = Self::MIN as i16;
        let max = Self::MAX as i16;
        if u < min {
            Err(TryFromIntError(IntErrorKind::NegOverflow))
        } else if u > max {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_both_bounded!(i16 => i8);
401#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i32> for i16 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: i32) -> Result<Self, Self::Error> {
        let min = Self::MIN as i32;
        let max = Self::MAX as i32;
        if u < min {
            Err(TryFromIntError(IntErrorKind::NegOverflow))
        } else if u > max {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_both_bounded!(i32 => i8, i16);
402#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i64> for i32 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: i64) -> Result<Self, Self::Error> {
        let min = Self::MIN as i64;
        let max = Self::MAX as i64;
        if u < min {
            Err(TryFromIntError(IntErrorKind::NegOverflow))
        } else if u > max {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_both_bounded!(i64 => i8, i16, i32);
403#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i128> for i64 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: i128) -> Result<Self, Self::Error> {
        let min = Self::MIN as i128;
        let max = Self::MAX as i128;
        if u < min {
            Err(TryFromIntError(IntErrorKind::NegOverflow))
        } else if u > max {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_both_bounded!(i128 => i8, i16, i32, i64);
404
405// unsigned integer -> signed integer
406#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u8> for i8 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: u8) -> Result<Self, Self::Error> {
        if u > (Self::MAX as u8) {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_upper_bounded!(u8 => i8);
407#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u16> for i16 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: u16) -> Result<Self, Self::Error> {
        if u > (Self::MAX as u16) {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_upper_bounded!(u16 => i8, i16);
408#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u32> for i32 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: u32) -> Result<Self, Self::Error> {
        if u > (Self::MAX as u32) {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_upper_bounded!(u32 => i8, i16, i32);
409#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u64> for i64 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: u64) -> Result<Self, Self::Error> {
        if u > (Self::MAX as u64) {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_upper_bounded!(u64 => i8, i16, i32, i64);
410#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u128> for i128 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: u128) -> Result<Self, Self::Error> {
        if u > (Self::MAX as u128) {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_upper_bounded!(u128 => i8, i16, i32, i64, i128);
411
412// signed integer -> unsigned integer
413#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i8> for u128 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: i8) -> Result<Self, Self::Error> {
        if u >= 0 {
            Ok(u as Self)
        } else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
    }
}impl_try_from_lower_bounded!(i8 => u8, u16, u32, u64, u128);
414#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i16> for u8 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: i16) -> Result<Self, Self::Error> {
        let min = Self::MIN as i16;
        let max = Self::MAX as i16;
        if u < min {
            Err(TryFromIntError(IntErrorKind::NegOverflow))
        } else if u > max {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_both_bounded!(i16 => u8);
415#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i16> for u128 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: i16) -> Result<Self, Self::Error> {
        if u >= 0 {
            Ok(u as Self)
        } else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
    }
}impl_try_from_lower_bounded!(i16 => u16, u32, u64, u128);
416#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i32> for u16 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: i32) -> Result<Self, Self::Error> {
        let min = Self::MIN as i32;
        let max = Self::MAX as i32;
        if u < min {
            Err(TryFromIntError(IntErrorKind::NegOverflow))
        } else if u > max {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_both_bounded!(i32 => u8, u16);
417#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i32> for u128 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: i32) -> Result<Self, Self::Error> {
        if u >= 0 {
            Ok(u as Self)
        } else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
    }
}impl_try_from_lower_bounded!(i32 => u32, u64, u128);
418#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i64> for u32 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: i64) -> Result<Self, Self::Error> {
        let min = Self::MIN as i64;
        let max = Self::MAX as i64;
        if u < min {
            Err(TryFromIntError(IntErrorKind::NegOverflow))
        } else if u > max {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_both_bounded!(i64 => u8, u16, u32);
419#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i64> for u128 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: i64) -> Result<Self, Self::Error> {
        if u >= 0 {
            Ok(u as Self)
        } else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
    }
}impl_try_from_lower_bounded!(i64 => u64, u128);
420#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i128> for u64 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: i128) -> Result<Self, Self::Error> {
        let min = Self::MIN as i128;
        let max = Self::MAX as i128;
        if u < min {
            Err(TryFromIntError(IntErrorKind::NegOverflow))
        } else if u > max {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_both_bounded!(i128 => u8, u16, u32, u64);
421#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i128> for u128 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: i128) -> Result<Self, Self::Error> {
        if u >= 0 {
            Ok(u as Self)
        } else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
    }
}impl_try_from_lower_bounded!(i128 => u128);
422
423// usize/isize
424#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<usize> for isize {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: usize) -> Result<Self, Self::Error> {
        if u > (Self::MAX as usize) {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_upper_bounded!(usize => isize);
425#[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<isize> for usize {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: isize) -> Result<Self, Self::Error> {
        if u >= 0 {
            Ok(u as Self)
        } else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
    }
}impl_try_from_lower_bounded!(isize => usize);
426
427#[cfg(target_pointer_width = "16")]
428mod ptr_try_from_impls {
429    use super::{IntErrorKind, TryFromIntError};
430
431    impl_try_from_upper_bounded!(usize => u8);
432    impl_try_from_unbounded!(usize => u16, u32, u64, u128);
433    impl_try_from_upper_bounded!(usize => i8, i16);
434    impl_try_from_unbounded!(usize => i32, i64, i128);
435
436    impl_try_from_both_bounded!(isize => u8);
437    impl_try_from_lower_bounded!(isize => u16, u32, u64, u128);
438    impl_try_from_both_bounded!(isize => i8);
439    impl_try_from_unbounded!(isize => i16, i32, i64, i128);
440
441    rev!(impl_try_from_upper_bounded, usize => u32, u64, u128);
442    rev!(impl_try_from_lower_bounded, usize => i8, i16);
443    rev!(impl_try_from_both_bounded, usize => i32, i64, i128);
444
445    rev!(impl_try_from_upper_bounded, isize => u16, u32, u64, u128);
446    rev!(impl_try_from_both_bounded, isize => i32, i64, i128);
447}
448
449#[cfg(target_pointer_width = "32")]
450mod ptr_try_from_impls {
451    use super::{IntErrorKind, TryFromIntError};
452
453    impl_try_from_upper_bounded!(usize => u8, u16);
454    impl_try_from_unbounded!(usize => u32, u64, u128);
455    impl_try_from_upper_bounded!(usize => i8, i16, i32);
456    impl_try_from_unbounded!(usize => i64, i128);
457
458    impl_try_from_both_bounded!(isize => u8, u16);
459    impl_try_from_lower_bounded!(isize => u32, u64, u128);
460    impl_try_from_both_bounded!(isize => i8, i16);
461    impl_try_from_unbounded!(isize => i32, i64, i128);
462
463    rev!(impl_try_from_unbounded, usize => u32);
464    rev!(impl_try_from_upper_bounded, usize => u64, u128);
465    rev!(impl_try_from_lower_bounded, usize => i8, i16, i32);
466    rev!(impl_try_from_both_bounded, usize => i64, i128);
467
468    rev!(impl_try_from_unbounded, isize => u16);
469    rev!(impl_try_from_upper_bounded, isize => u32, u64, u128);
470    rev!(impl_try_from_unbounded, isize => i32);
471    rev!(impl_try_from_both_bounded, isize => i64, i128);
472}
473
474#[cfg(target_pointer_width = "64")]
475mod ptr_try_from_impls {
476    use super::{IntErrorKind, TryFromIntError};
477
478    #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<usize> for u32 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: usize) -> Result<Self, Self::Error> {
        if u > (Self::MAX as usize) {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_upper_bounded!(usize => u8, u16, u32);
479    #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<usize> for u128 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(value: usize) -> Result<Self, Self::Error> {
        Ok(value as Self)
    }
}impl_try_from_unbounded!(usize => u64, u128);
480    #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<usize> for i64 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: usize) -> Result<Self, Self::Error> {
        if u > (Self::MAX as usize) {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_upper_bounded!(usize => i8, i16, i32, i64);
481    #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<usize> for i128 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(value: usize) -> Result<Self, Self::Error> {
        Ok(value as Self)
    }
}impl_try_from_unbounded!(usize => i128);
482
483    #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<isize> for u32 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: isize) -> Result<Self, Self::Error> {
        let min = Self::MIN as isize;
        let max = Self::MAX as isize;
        if u < min {
            Err(TryFromIntError(IntErrorKind::NegOverflow))
        } else if u > max {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_both_bounded!(isize => u8, u16, u32);
484    #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<isize> for u128 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: isize) -> Result<Self, Self::Error> {
        if u >= 0 {
            Ok(u as Self)
        } else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
    }
}impl_try_from_lower_bounded!(isize => u64, u128);
485    #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<isize> for i32 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: isize) -> Result<Self, Self::Error> {
        let min = Self::MIN as isize;
        let max = Self::MAX as isize;
        if u < min {
            Err(TryFromIntError(IntErrorKind::NegOverflow))
        } else if u > max {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}impl_try_from_both_bounded!(isize => i8, i16, i32);
486    #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<isize> for i128 {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(value: isize) -> Result<Self, Self::Error> {
        Ok(value as Self)
    }
}impl_try_from_unbounded!(isize => i64, i128);
487
488    #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u64> for usize {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(value: u64) -> Result<Self, Self::Error> { Ok(value as Self) }
}rev!(impl_try_from_unbounded, usize => u32, u64);
489    #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u128> for usize {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: u128) -> Result<Self, Self::Error> {
        if u > (Self::MAX as u128) {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}rev!(impl_try_from_upper_bounded, usize => u128);
490    #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i64> for usize {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: i64) -> Result<Self, Self::Error> {
        if u >= 0 {
            Ok(u as Self)
        } else { Err(TryFromIntError(IntErrorKind::NegOverflow)) }
    }
}rev!(impl_try_from_lower_bounded, usize => i8, i16, i32, i64);
491    #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i128> for usize {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: i128) -> Result<Self, Self::Error> {
        let min = Self::MIN as i128;
        let max = Self::MAX as i128;
        if u < min {
            Err(TryFromIntError(IntErrorKind::NegOverflow))
        } else if u > max {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}rev!(impl_try_from_both_bounded, usize => i128);
492
493    #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u32> for isize {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(value: u32) -> Result<Self, Self::Error> { Ok(value as Self) }
}rev!(impl_try_from_unbounded, isize => u16, u32);
494    #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u128> for isize {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: u128) -> Result<Self, Self::Error> {
        if u > (Self::MAX as u128) {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}rev!(impl_try_from_upper_bounded, isize => u64, u128);
495    #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i64> for isize {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(value: i64) -> Result<Self, Self::Error> { Ok(value as Self) }
}rev!(impl_try_from_unbounded, isize => i32, i64);
496    #[stable(feature = "try_from", since = "1.34.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i128> for isize {
    type Error = TryFromIntError;
    /// Tries to create the target number type from a source
    /// number type. This returns an error if the source value
    /// is outside of the range of the target type.
    #[inline]
    fn try_from(u: i128) -> Result<Self, Self::Error> {
        let min = Self::MIN as i128;
        let max = Self::MAX as i128;
        if u < min {
            Err(TryFromIntError(IntErrorKind::NegOverflow))
        } else if u > max {
            Err(TryFromIntError(IntErrorKind::PosOverflow))
        } else { Ok(u as Self) }
    }
}rev!(impl_try_from_both_bounded, isize => i128);
497}
498
499// Conversion traits for non-zero integer types
500use crate::num::NonZero;
501
502macro_rules! impl_nonzero_int_from_nonzero_int {
503    ($Small:ty => $Large:ty) => {
504        #[stable(feature = "nz_int_conv", since = "1.41.0")]
505        #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
506        impl const From<NonZero<$Small>> for NonZero<$Large> {
507            // Rustdocs on the impl block show a "[+] show undocumented items" toggle.
508            // Rustdocs on functions do not.
509            #[doc = concat!("Converts <code>[NonZero]\\<[", stringify!($Small), "]></code> ")]
510            #[doc = concat!("to <code>[NonZero]\\<[", stringify!($Large), "]></code> losslessly.")]
511            #[inline]
512            fn from(small: NonZero<$Small>) -> Self {
513                // SAFETY: input type guarantees the value is non-zero
514                unsafe { Self::new_unchecked(From::from(small.get())) }
515            }
516        }
517    };
518}
519
520// non-zero unsigned integer -> non-zero unsigned integer
521#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<u16> {
    #[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
    #[doc = "to <code>[NonZero]\\<[u16]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u8>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u8 => u16);
522#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<u32> {
    #[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
    #[doc = "to <code>[NonZero]\\<[u32]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u8>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u8 => u32);
523#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<u64> {
    #[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
    #[doc = "to <code>[NonZero]\\<[u64]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u8>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u8 => u64);
524#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<u128> {
    #[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
    #[doc = "to <code>[NonZero]\\<[u128]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u8>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u8 => u128);
525#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<usize> {
    #[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
    #[doc = "to <code>[NonZero]\\<[usize]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u8>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u8 => usize);
526#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u16>> for NonZero<u32> {
    #[doc = "Converts <code>[NonZero]\\<[u16]></code> "]
    #[doc = "to <code>[NonZero]\\<[u32]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u16>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u16 => u32);
527#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u16>> for NonZero<u64> {
    #[doc = "Converts <code>[NonZero]\\<[u16]></code> "]
    #[doc = "to <code>[NonZero]\\<[u64]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u16>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u16 => u64);
528#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u16>> for NonZero<u128> {
    #[doc = "Converts <code>[NonZero]\\<[u16]></code> "]
    #[doc = "to <code>[NonZero]\\<[u128]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u16>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u16 => u128);
529#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u16>> for NonZero<usize> {
    #[doc = "Converts <code>[NonZero]\\<[u16]></code> "]
    #[doc = "to <code>[NonZero]\\<[usize]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u16>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u16 => usize);
530#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u32>> for NonZero<u64> {
    #[doc = "Converts <code>[NonZero]\\<[u32]></code> "]
    #[doc = "to <code>[NonZero]\\<[u64]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u32>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u32 => u64);
531#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u32>> for NonZero<u128> {
    #[doc = "Converts <code>[NonZero]\\<[u32]></code> "]
    #[doc = "to <code>[NonZero]\\<[u128]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u32>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u32 => u128);
532#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u64>> for NonZero<u128> {
    #[doc = "Converts <code>[NonZero]\\<[u64]></code> "]
    #[doc = "to <code>[NonZero]\\<[u128]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u64>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u64 => u128);
533
534// non-zero signed integer -> non-zero signed integer
535#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i8>> for NonZero<i16> {
    #[doc = "Converts <code>[NonZero]\\<[i8]></code> "]
    #[doc = "to <code>[NonZero]\\<[i16]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<i8>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(i8 => i16);
536#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i8>> for NonZero<i32> {
    #[doc = "Converts <code>[NonZero]\\<[i8]></code> "]
    #[doc = "to <code>[NonZero]\\<[i32]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<i8>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(i8 => i32);
537#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i8>> for NonZero<i64> {
    #[doc = "Converts <code>[NonZero]\\<[i8]></code> "]
    #[doc = "to <code>[NonZero]\\<[i64]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<i8>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(i8 => i64);
538#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i8>> for NonZero<i128> {
    #[doc = "Converts <code>[NonZero]\\<[i8]></code> "]
    #[doc = "to <code>[NonZero]\\<[i128]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<i8>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(i8 => i128);
539#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i8>> for NonZero<isize> {
    #[doc = "Converts <code>[NonZero]\\<[i8]></code> "]
    #[doc = "to <code>[NonZero]\\<[isize]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<i8>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(i8 => isize);
540#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i16>> for NonZero<i32> {
    #[doc = "Converts <code>[NonZero]\\<[i16]></code> "]
    #[doc = "to <code>[NonZero]\\<[i32]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<i16>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(i16 => i32);
541#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i16>> for NonZero<i64> {
    #[doc = "Converts <code>[NonZero]\\<[i16]></code> "]
    #[doc = "to <code>[NonZero]\\<[i64]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<i16>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(i16 => i64);
542#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i16>> for NonZero<i128> {
    #[doc = "Converts <code>[NonZero]\\<[i16]></code> "]
    #[doc = "to <code>[NonZero]\\<[i128]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<i16>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(i16 => i128);
543#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i16>> for NonZero<isize> {
    #[doc = "Converts <code>[NonZero]\\<[i16]></code> "]
    #[doc = "to <code>[NonZero]\\<[isize]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<i16>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(i16 => isize);
544#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i32>> for NonZero<i64> {
    #[doc = "Converts <code>[NonZero]\\<[i32]></code> "]
    #[doc = "to <code>[NonZero]\\<[i64]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<i32>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(i32 => i64);
545#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i32>> for NonZero<i128> {
    #[doc = "Converts <code>[NonZero]\\<[i32]></code> "]
    #[doc = "to <code>[NonZero]\\<[i128]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<i32>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(i32 => i128);
546#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<i64>> for NonZero<i128> {
    #[doc = "Converts <code>[NonZero]\\<[i64]></code> "]
    #[doc = "to <code>[NonZero]\\<[i128]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<i64>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(i64 => i128);
547
548// non-zero unsigned -> non-zero signed integer
549#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<i16> {
    #[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
    #[doc = "to <code>[NonZero]\\<[i16]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u8>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u8 => i16);
550#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<i32> {
    #[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
    #[doc = "to <code>[NonZero]\\<[i32]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u8>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u8 => i32);
551#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<i64> {
    #[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
    #[doc = "to <code>[NonZero]\\<[i64]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u8>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u8 => i64);
552#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<i128> {
    #[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
    #[doc = "to <code>[NonZero]\\<[i128]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u8>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u8 => i128);
553#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u8>> for NonZero<isize> {
    #[doc = "Converts <code>[NonZero]\\<[u8]></code> "]
    #[doc = "to <code>[NonZero]\\<[isize]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u8>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u8 => isize);
554#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u16>> for NonZero<i32> {
    #[doc = "Converts <code>[NonZero]\\<[u16]></code> "]
    #[doc = "to <code>[NonZero]\\<[i32]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u16>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u16 => i32);
555#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u16>> for NonZero<i64> {
    #[doc = "Converts <code>[NonZero]\\<[u16]></code> "]
    #[doc = "to <code>[NonZero]\\<[i64]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u16>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u16 => i64);
556#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u16>> for NonZero<i128> {
    #[doc = "Converts <code>[NonZero]\\<[u16]></code> "]
    #[doc = "to <code>[NonZero]\\<[i128]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u16>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u16 => i128);
557#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u32>> for NonZero<i64> {
    #[doc = "Converts <code>[NonZero]\\<[u32]></code> "]
    #[doc = "to <code>[NonZero]\\<[i64]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u32>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u32 => i64);
558#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u32>> for NonZero<i128> {
    #[doc = "Converts <code>[NonZero]\\<[u32]></code> "]
    #[doc = "to <code>[NonZero]\\<[i128]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u32>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u32 => i128);
559#[stable(feature = "nz_int_conv", since = "1.41.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const From<NonZero<u64>> for NonZero<i128> {
    #[doc = "Converts <code>[NonZero]\\<[u64]></code> "]
    #[doc = "to <code>[NonZero]\\<[i128]></code> losslessly."]
    #[inline]
    fn from(small: NonZero<u64>) -> Self {
        unsafe { Self::new_unchecked(From::from(small.get())) }
    }
}impl_nonzero_int_from_nonzero_int!(u64 => i128);
560
561macro_rules! impl_nonzero_int_try_from_int {
562    ($Int:ty) => {
563        #[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
564        #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
565        impl const TryFrom<$Int> for NonZero<$Int> {
566            type Error = TryFromIntError;
567
568            // Rustdocs on the impl block show a "[+] show undocumented items" toggle.
569            // Rustdocs on functions do not.
570            #[doc = concat!("Attempts to convert [`", stringify!($Int), "`] ")]
571            #[doc = concat!("to <code>[NonZero]\\<[", stringify!($Int), "]></code>.")]
572            #[inline]
573            fn try_from(value: $Int) -> Result<Self, Self::Error> {
574                Self::new(value).ok_or(TryFromIntError(IntErrorKind::Zero))
575            }
576        }
577    };
578}
579
580// integer -> non-zero integer
581#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u8> for NonZero<u8> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert [`u8`] "]
    #[doc = "to <code>[NonZero]\\<[u8]></code>."]
    #[inline]
    fn try_from(value: u8) -> Result<Self, Self::Error> {
        Self::new(value).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}impl_nonzero_int_try_from_int!(u8);
582#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u16> for NonZero<u16> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert [`u16`] "]
    #[doc = "to <code>[NonZero]\\<[u16]></code>."]
    #[inline]
    fn try_from(value: u16) -> Result<Self, Self::Error> {
        Self::new(value).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}impl_nonzero_int_try_from_int!(u16);
583#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u32> for NonZero<u32> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert [`u32`] "]
    #[doc = "to <code>[NonZero]\\<[u32]></code>."]
    #[inline]
    fn try_from(value: u32) -> Result<Self, Self::Error> {
        Self::new(value).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}impl_nonzero_int_try_from_int!(u32);
584#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u64> for NonZero<u64> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert [`u64`] "]
    #[doc = "to <code>[NonZero]\\<[u64]></code>."]
    #[inline]
    fn try_from(value: u64) -> Result<Self, Self::Error> {
        Self::new(value).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}impl_nonzero_int_try_from_int!(u64);
585#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<u128> for NonZero<u128> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert [`u128`] "]
    #[doc = "to <code>[NonZero]\\<[u128]></code>."]
    #[inline]
    fn try_from(value: u128) -> Result<Self, Self::Error> {
        Self::new(value).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}impl_nonzero_int_try_from_int!(u128);
586#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<usize> for NonZero<usize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert [`usize`] "]
    #[doc = "to <code>[NonZero]\\<[usize]></code>."]
    #[inline]
    fn try_from(value: usize) -> Result<Self, Self::Error> {
        Self::new(value).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}impl_nonzero_int_try_from_int!(usize);
587#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i8> for NonZero<i8> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert [`i8`] "]
    #[doc = "to <code>[NonZero]\\<[i8]></code>."]
    #[inline]
    fn try_from(value: i8) -> Result<Self, Self::Error> {
        Self::new(value).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}impl_nonzero_int_try_from_int!(i8);
588#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i16> for NonZero<i16> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert [`i16`] "]
    #[doc = "to <code>[NonZero]\\<[i16]></code>."]
    #[inline]
    fn try_from(value: i16) -> Result<Self, Self::Error> {
        Self::new(value).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}impl_nonzero_int_try_from_int!(i16);
589#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i32> for NonZero<i32> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert [`i32`] "]
    #[doc = "to <code>[NonZero]\\<[i32]></code>."]
    #[inline]
    fn try_from(value: i32) -> Result<Self, Self::Error> {
        Self::new(value).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}impl_nonzero_int_try_from_int!(i32);
590#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i64> for NonZero<i64> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert [`i64`] "]
    #[doc = "to <code>[NonZero]\\<[i64]></code>."]
    #[inline]
    fn try_from(value: i64) -> Result<Self, Self::Error> {
        Self::new(value).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}impl_nonzero_int_try_from_int!(i64);
591#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<i128> for NonZero<i128> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert [`i128`] "]
    #[doc = "to <code>[NonZero]\\<[i128]></code>."]
    #[inline]
    fn try_from(value: i128) -> Result<Self, Self::Error> {
        Self::new(value).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}impl_nonzero_int_try_from_int!(i128);
592#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<isize> for NonZero<isize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert [`isize`] "]
    #[doc = "to <code>[NonZero]\\<[isize]></code>."]
    #[inline]
    fn try_from(value: isize) -> Result<Self, Self::Error> {
        Self::new(value).ok_or(TryFromIntError(IntErrorKind::Zero))
    }
}impl_nonzero_int_try_from_int!(isize);
593
594macro_rules! impl_nonzero_int_try_from_nonzero_int {
595    ($source:ty => $($target:ty),+) => {$(
596        #[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
597        #[rustc_const_unstable(feature = "const_convert", issue = "143773")]
598        impl const TryFrom<NonZero<$source>> for NonZero<$target> {
599            type Error = TryFromIntError;
600
601            // Rustdocs on the impl block show a "[+] show undocumented items" toggle.
602            // Rustdocs on functions do not.
603            #[doc = concat!("Attempts to convert <code>[NonZero]\\<[", stringify!($source), "]></code> ")]
604            #[doc = concat!("to <code>[NonZero]\\<[", stringify!($target), "]></code>.")]
605            #[inline]
606            fn try_from(value: NonZero<$source>) -> Result<Self, Self::Error> {
607                // SAFETY: Input is guaranteed to be non-zero.
608                Ok(unsafe { Self::new_unchecked(<$target>::try_from(value.get())?) })
609            }
610        }
611    )*};
612}
613
614// unsigned non-zero integer -> unsigned non-zero integer
615#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<u16>> for NonZero<u8> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[u16]></code> "]
    #[doc = "to <code>[NonZero]\\<[u8]></code>."]
    #[inline]
    fn try_from(value: NonZero<u16>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<u8>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(u16 => u8);
616#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<u32>> for NonZero<usize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[u32]></code> "]
    #[doc = "to <code>[NonZero]\\<[usize]></code>."]
    #[inline]
    fn try_from(value: NonZero<u32>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<usize>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(u32 => u8, u16, usize);
617#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<u64>> for NonZero<usize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[u64]></code> "]
    #[doc = "to <code>[NonZero]\\<[usize]></code>."]
    #[inline]
    fn try_from(value: NonZero<u64>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<usize>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(u64 => u8, u16, u32, usize);
618#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<u128>> for NonZero<usize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[u128]></code> "]
    #[doc = "to <code>[NonZero]\\<[usize]></code>."]
    #[inline]
    fn try_from(value: NonZero<u128>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<usize>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(u128 => u8, u16, u32, u64, usize);
619#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<usize>> for NonZero<u128> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[usize]></code> "]
    #[doc = "to <code>[NonZero]\\<[u128]></code>."]
    #[inline]
    fn try_from(value: NonZero<usize>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<u128>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(usize => u8, u16, u32, u64, u128);
620
621// signed non-zero integer -> signed non-zero integer
622#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<i16>> for NonZero<i8> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[i16]></code> "]
    #[doc = "to <code>[NonZero]\\<[i8]></code>."]
    #[inline]
    fn try_from(value: NonZero<i16>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<i8>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(i16 => i8);
623#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<i32>> for NonZero<isize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[i32]></code> "]
    #[doc = "to <code>[NonZero]\\<[isize]></code>."]
    #[inline]
    fn try_from(value: NonZero<i32>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<isize>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(i32 => i8, i16, isize);
624#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<i64>> for NonZero<isize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[i64]></code> "]
    #[doc = "to <code>[NonZero]\\<[isize]></code>."]
    #[inline]
    fn try_from(value: NonZero<i64>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<isize>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(i64 => i8, i16, i32, isize);
625#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<i128>> for NonZero<isize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[i128]></code> "]
    #[doc = "to <code>[NonZero]\\<[isize]></code>."]
    #[inline]
    fn try_from(value: NonZero<i128>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<isize>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(i128 => i8, i16, i32, i64, isize);
626#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<isize>> for NonZero<i128> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[isize]></code> "]
    #[doc = "to <code>[NonZero]\\<[i128]></code>."]
    #[inline]
    fn try_from(value: NonZero<isize>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<i128>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(isize => i8, i16, i32, i64, i128);
627
628// unsigned non-zero integer -> signed non-zero integer
629#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<u8>> for NonZero<i8> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[u8]></code> "]
    #[doc = "to <code>[NonZero]\\<[i8]></code>."]
    #[inline]
    fn try_from(value: NonZero<u8>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<i8>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(u8 => i8);
630#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<u16>> for NonZero<isize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[u16]></code> "]
    #[doc = "to <code>[NonZero]\\<[isize]></code>."]
    #[inline]
    fn try_from(value: NonZero<u16>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<isize>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(u16 => i8, i16, isize);
631#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<u32>> for NonZero<isize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[u32]></code> "]
    #[doc = "to <code>[NonZero]\\<[isize]></code>."]
    #[inline]
    fn try_from(value: NonZero<u32>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<isize>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(u32 => i8, i16, i32, isize);
632#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<u64>> for NonZero<isize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[u64]></code> "]
    #[doc = "to <code>[NonZero]\\<[isize]></code>."]
    #[inline]
    fn try_from(value: NonZero<u64>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<isize>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(u64 => i8, i16, i32, i64, isize);
633#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<u128>> for NonZero<isize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[u128]></code> "]
    #[doc = "to <code>[NonZero]\\<[isize]></code>."]
    #[inline]
    fn try_from(value: NonZero<u128>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<isize>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(u128 => i8, i16, i32, i64, i128, isize);
634#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<usize>> for NonZero<isize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[usize]></code> "]
    #[doc = "to <code>[NonZero]\\<[isize]></code>."]
    #[inline]
    fn try_from(value: NonZero<usize>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<isize>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(usize => i8, i16, i32, i64, i128, isize);
635
636// signed non-zero integer -> unsigned non-zero integer
637#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<i8>> for NonZero<usize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[i8]></code> "]
    #[doc = "to <code>[NonZero]\\<[usize]></code>."]
    #[inline]
    fn try_from(value: NonZero<i8>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<usize>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(i8 => u8, u16, u32, u64, u128, usize);
638#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<i16>> for NonZero<usize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[i16]></code> "]
    #[doc = "to <code>[NonZero]\\<[usize]></code>."]
    #[inline]
    fn try_from(value: NonZero<i16>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<usize>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(i16 => u8, u16, u32, u64, u128, usize);
639#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<i32>> for NonZero<usize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[i32]></code> "]
    #[doc = "to <code>[NonZero]\\<[usize]></code>."]
    #[inline]
    fn try_from(value: NonZero<i32>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<usize>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(i32 => u8, u16, u32, u64, u128, usize);
640#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<i64>> for NonZero<usize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[i64]></code> "]
    #[doc = "to <code>[NonZero]\\<[usize]></code>."]
    #[inline]
    fn try_from(value: NonZero<i64>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<usize>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(i64 => u8, u16, u32, u64, u128, usize);
641#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<i128>> for NonZero<usize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[i128]></code> "]
    #[doc = "to <code>[NonZero]\\<[usize]></code>."]
    #[inline]
    fn try_from(value: NonZero<i128>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<usize>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(i128 => u8, u16, u32, u64, u128, usize);
642#[stable(feature = "nzint_try_from_nzint_conv", since = "1.49.0")]
#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
impl const TryFrom<NonZero<isize>> for NonZero<usize> {
    type Error = TryFromIntError;
    #[doc = "Attempts to convert <code>[NonZero]\\<[isize]></code> "]
    #[doc = "to <code>[NonZero]\\<[usize]></code>."]
    #[inline]
    fn try_from(value: NonZero<isize>) -> Result<Self, Self::Error> {
        Ok(unsafe { Self::new_unchecked(<usize>::try_from(value.get())?) })
    }
}impl_nonzero_int_try_from_nonzero_int!(isize => u8, u16, u32, u64, u128, usize);