@@ -3647,7 +3647,7 @@ macro_rules! from_str_radix_int_impl {
36473647from_str_radix_int_impl ! { isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128 }
36483648
36493649/// The error type returned when a checked integral type conversion fails.
3650- #[ unstable ( feature = "try_from" , issue = "33417 " ) ]
3650+ #[ stable ( feature = "try_from" , since = "1.26.0 " ) ]
36513651#[ derive( Debug , Copy , Clone ) ]
36523652pub struct TryFromIntError ( ( ) ) ;
36533653
@@ -3662,39 +3662,24 @@ impl TryFromIntError {
36623662 }
36633663}
36643664
3665- #[ unstable ( feature = "try_from" , issue = "33417 " ) ]
3665+ #[ stable ( feature = "try_from" , since = "1.26.0 " ) ]
36663666impl fmt:: Display for TryFromIntError {
36673667 fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
36683668 self . __description ( ) . fmt ( fmt)
36693669 }
36703670}
36713671
3672- #[ unstable ( feature = "try_from" , issue = "33417 " ) ]
3672+ #[ stable ( feature = "try_from" , since = "1.26.0 " ) ]
36733673impl From < !> for TryFromIntError {
36743674 fn from ( never : !) -> TryFromIntError {
36753675 never
36763676 }
36773677}
36783678
3679- // no possible bounds violation
3680- macro_rules! try_from_unbounded {
3681- ( $source: ty, $( $target: ty) ,* ) => { $(
3682- #[ unstable( feature = "try_from" , issue = "33417" ) ]
3683- impl TryFrom <$source> for $target {
3684- type Error = !;
3685-
3686- #[ inline]
3687- fn try_from( value: $source) -> Result <Self , Self :: Error > {
3688- Ok ( value as $target)
3689- }
3690- }
3691- ) * }
3692- }
3693-
36943679// only negative bounds
36953680macro_rules! try_from_lower_bounded {
36963681 ( $source: ty, $( $target: ty) ,* ) => { $(
3697- #[ unstable ( feature = "try_from" , issue = "33417 " ) ]
3682+ #[ stable ( feature = "try_from" , since = "1.26.0 " ) ]
36983683 impl TryFrom <$source> for $target {
36993684 type Error = TryFromIntError ;
37003685
@@ -3713,7 +3698,7 @@ macro_rules! try_from_lower_bounded {
37133698// unsigned to signed (only positive bound)
37143699macro_rules! try_from_upper_bounded {
37153700 ( $source: ty, $( $target: ty) ,* ) => { $(
3716- #[ unstable ( feature = "try_from" , issue = "33417 " ) ]
3701+ #[ stable ( feature = "try_from" , since = "1.26.0 " ) ]
37173702 impl TryFrom <$source> for $target {
37183703 type Error = TryFromIntError ;
37193704
@@ -3732,7 +3717,7 @@ macro_rules! try_from_upper_bounded {
37323717// all other cases
37333718macro_rules! try_from_both_bounded {
37343719 ( $source: ty, $( $target: ty) ,* ) => { $(
3735- #[ unstable ( feature = "try_from" , issue = "33417 " ) ]
3720+ #[ stable ( feature = "try_from" , since = "1.26.0 " ) ]
37363721 impl TryFrom <$source> for $target {
37373722 type Error = TryFromIntError ;
37383723
@@ -3789,82 +3774,44 @@ try_from_both_bounded!(i128, u64, u32, u16, u8);
37893774try_from_upper_bounded ! ( usize , isize ) ;
37903775try_from_lower_bounded ! ( isize , usize ) ;
37913776
3777+ try_from_upper_bounded ! ( usize , u8 ) ;
3778+ try_from_upper_bounded ! ( usize , i8 , i16 ) ;
3779+ try_from_both_bounded ! ( isize , u8 ) ;
3780+ try_from_both_bounded ! ( isize , i8 ) ;
3781+
37923782#[ cfg( target_pointer_width = "16" ) ]
37933783mod ptr_try_from_impls {
37943784 use super :: TryFromIntError ;
37953785 use convert:: TryFrom ;
37963786
3797- try_from_upper_bounded ! ( usize , u8 ) ;
3798- try_from_unbounded ! ( usize , u16 , u32 , u64 , u128 ) ;
3799- try_from_upper_bounded ! ( usize , i8 , i16 ) ;
3800- try_from_unbounded ! ( usize , i32 , i64 , i128 ) ;
3801-
3802- try_from_both_bounded ! ( isize , u8 ) ;
3787+ // Fallible across platfoms, only implementation differs
38033788 try_from_lower_bounded ! ( isize , u16 , u32 , u64 , u128 ) ;
3804- try_from_both_bounded ! ( isize , i8 ) ;
3805- try_from_unbounded ! ( isize , i16 , i32 , i64 , i128 ) ;
3806-
3807- rev ! ( try_from_unbounded, usize , u16 ) ;
3808- rev ! ( try_from_upper_bounded, usize , u32 , u64 , u128 ) ;
38093789 rev ! ( try_from_lower_bounded, usize , i8 , i16 ) ;
38103790 rev ! ( try_from_both_bounded, usize , i32 , i64 , i128 ) ;
3811-
3812- rev ! ( try_from_unbounded, isize , u8 ) ;
3813- rev ! ( try_from_upper_bounded, isize , u16 , u32 , u64 , u128 ) ;
3814- rev ! ( try_from_unbounded, isize , i16 ) ;
3815- rev ! ( try_from_both_bounded, isize , i32 , i64 , i128 ) ;
38163791}
38173792
38183793#[ cfg( target_pointer_width = "32" ) ]
38193794mod ptr_try_from_impls {
38203795 use super :: TryFromIntError ;
38213796 use convert:: TryFrom ;
38223797
3823- try_from_upper_bounded ! ( usize , u8 , u16 ) ;
3824- try_from_unbounded ! ( usize , u32 , u64 , u128 ) ;
3825- try_from_upper_bounded ! ( usize , i8 , i16 , i32 ) ;
3826- try_from_unbounded ! ( usize , i64 , i128 ) ;
3827-
3828- try_from_both_bounded ! ( isize , u8 , u16 ) ;
3798+ // Fallible across platfoms, only implementation differs
3799+ try_from_both_bounded ! ( isize , u16 ) ;
38293800 try_from_lower_bounded ! ( isize , u32 , u64 , u128 ) ;
3830- try_from_both_bounded ! ( isize , i8 , i16 ) ;
3831- try_from_unbounded ! ( isize , i32 , i64 , i128 ) ;
3832-
3833- rev ! ( try_from_unbounded, usize , u16 , u32 ) ;
3834- rev ! ( try_from_upper_bounded, usize , u64 , u128 ) ;
38353801 rev ! ( try_from_lower_bounded, usize , i8 , i16 , i32 ) ;
38363802 rev ! ( try_from_both_bounded, usize , i64 , i128 ) ;
3837-
3838- rev ! ( try_from_unbounded, isize , u8 , u16 ) ;
3839- rev ! ( try_from_upper_bounded, isize , u32 , u64 , u128 ) ;
3840- rev ! ( try_from_unbounded, isize , i16 , i32 ) ;
3841- rev ! ( try_from_both_bounded, isize , i64 , i128 ) ;
38423803}
38433804
38443805#[ cfg( target_pointer_width = "64" ) ]
38453806mod ptr_try_from_impls {
38463807 use super :: TryFromIntError ;
38473808 use convert:: TryFrom ;
38483809
3849- try_from_upper_bounded ! ( usize , u8 , u16 , u32 ) ;
3850- try_from_unbounded ! ( usize , u64 , u128 ) ;
3851- try_from_upper_bounded ! ( usize , i8 , i16 , i32 , i64 ) ;
3852- try_from_unbounded ! ( usize , i128 ) ;
3853-
3854- try_from_both_bounded ! ( isize , u8 , u16 , u32 ) ;
3810+ // Fallible across platfoms, only implementation differs
3811+ try_from_both_bounded ! ( isize , u16 , u32 ) ;
38553812 try_from_lower_bounded ! ( isize , u64 , u128 ) ;
3856- try_from_both_bounded ! ( isize , i8 , i16 , i32 ) ;
3857- try_from_unbounded ! ( isize , i64 , i128 ) ;
3858-
3859- rev ! ( try_from_unbounded, usize , u16 , u32 , u64 ) ;
3860- rev ! ( try_from_upper_bounded, usize , u128 ) ;
38613813 rev ! ( try_from_lower_bounded, usize , i8 , i16 , i32 , i64 ) ;
38623814 rev ! ( try_from_both_bounded, usize , i128 ) ;
3863-
3864- rev ! ( try_from_unbounded, isize , u8 , u16 , u32 ) ;
3865- rev ! ( try_from_upper_bounded, isize , u64 , u128 ) ;
3866- rev ! ( try_from_unbounded, isize , i16 , i32 , i64 ) ;
3867- rev ! ( try_from_both_bounded, isize , i128 ) ;
38683815}
38693816
38703817#[ doc( hidden) ]
@@ -4074,6 +4021,20 @@ impl_from! { u32, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]
40744021impl_from ! { u32 , i128 , #[ stable( feature = "i128" , since = "1.26.0" ) ] }
40754022impl_from ! { u64 , i128 , #[ stable( feature = "i128" , since = "1.26.0" ) ] }
40764023
4024+ // The C99 standard defines bounds on INTPTR_MIN, INTPTR_MAX, and UINTPTR_MAX
4025+ // which imply that pointer-sized integers must be at least 16 bits:
4026+ // https://port70.net/~nsz/c/c99/n1256.html#7.18.2.4
4027+ impl_from ! { u16 , usize , #[ stable( feature = "lossless_iusize_conv" , since = "1.26.0" ) ] }
4028+ impl_from ! { u8 , isize , #[ stable( feature = "lossless_iusize_conv" , since = "1.26.0" ) ] }
4029+ impl_from ! { i16 , isize , #[ stable( feature = "lossless_iusize_conv" , since = "1.26.0" ) ] }
4030+
4031+ // RISC-V defines the possibility of a 128-bit address space (RV128).
4032+
4033+ // CHERI proposes 256-bit “capabilities”. Unclear if this would be relevant to usize/isize.
4034+ // https://www.cl.cam.ac.uk/research/security/ctsrd/pdfs/20171017a-cheri-poster.pdf
4035+ // http://www.csl.sri.com/users/neumann/2012resolve-cheri.pdf
4036+
4037+
40774038// Note: integers can only be represented with full precision in a float if
40784039// they fit in the significand, which is 24 bits in f32 and 53 bits in f64.
40794040// Lossy float conversions are not implemented at this time.
0 commit comments