@@ -3647,7 +3647,7 @@ macro_rules! from_str_radix_int_impl {
3647
3647
from_str_radix_int_impl ! { isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128 }
3648
3648
3649
3649
/// 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 " ) ]
3651
3651
#[ derive( Debug , Copy , Clone ) ]
3652
3652
pub struct TryFromIntError ( ( ) ) ;
3653
3653
@@ -3662,39 +3662,24 @@ impl TryFromIntError {
3662
3662
}
3663
3663
}
3664
3664
3665
- #[ unstable ( feature = "try_from" , issue = "33417 " ) ]
3665
+ #[ stable ( feature = "try_from" , since = "1.26.0 " ) ]
3666
3666
impl fmt:: Display for TryFromIntError {
3667
3667
fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
3668
3668
self . __description ( ) . fmt ( fmt)
3669
3669
}
3670
3670
}
3671
3671
3672
- #[ unstable ( feature = "try_from" , issue = "33417 " ) ]
3672
+ #[ stable ( feature = "try_from" , since = "1.26.0 " ) ]
3673
3673
impl From < !> for TryFromIntError {
3674
3674
fn from ( never : !) -> TryFromIntError {
3675
3675
never
3676
3676
}
3677
3677
}
3678
3678
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
-
3694
3679
// only negative bounds
3695
3680
macro_rules! try_from_lower_bounded {
3696
3681
( $source: ty, $( $target: ty) ,* ) => { $(
3697
- #[ unstable ( feature = "try_from" , issue = "33417 " ) ]
3682
+ #[ stable ( feature = "try_from" , since = "1.26.0 " ) ]
3698
3683
impl TryFrom <$source> for $target {
3699
3684
type Error = TryFromIntError ;
3700
3685
@@ -3713,7 +3698,7 @@ macro_rules! try_from_lower_bounded {
3713
3698
// unsigned to signed (only positive bound)
3714
3699
macro_rules! try_from_upper_bounded {
3715
3700
( $source: ty, $( $target: ty) ,* ) => { $(
3716
- #[ unstable ( feature = "try_from" , issue = "33417 " ) ]
3701
+ #[ stable ( feature = "try_from" , since = "1.26.0 " ) ]
3717
3702
impl TryFrom <$source> for $target {
3718
3703
type Error = TryFromIntError ;
3719
3704
@@ -3732,7 +3717,7 @@ macro_rules! try_from_upper_bounded {
3732
3717
// all other cases
3733
3718
macro_rules! try_from_both_bounded {
3734
3719
( $source: ty, $( $target: ty) ,* ) => { $(
3735
- #[ unstable ( feature = "try_from" , issue = "33417 " ) ]
3720
+ #[ stable ( feature = "try_from" , since = "1.26.0 " ) ]
3736
3721
impl TryFrom <$source> for $target {
3737
3722
type Error = TryFromIntError ;
3738
3723
@@ -3789,82 +3774,44 @@ try_from_both_bounded!(i128, u64, u32, u16, u8);
3789
3774
try_from_upper_bounded ! ( usize , isize ) ;
3790
3775
try_from_lower_bounded ! ( isize , usize ) ;
3791
3776
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
+
3792
3782
#[ cfg( target_pointer_width = "16" ) ]
3793
3783
mod ptr_try_from_impls {
3794
3784
use super :: TryFromIntError ;
3795
3785
use convert:: TryFrom ;
3796
3786
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
3803
3788
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 ) ;
3809
3789
rev ! ( try_from_lower_bounded, usize , i8 , i16 ) ;
3810
3790
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 ) ;
3816
3791
}
3817
3792
3818
3793
#[ cfg( target_pointer_width = "32" ) ]
3819
3794
mod ptr_try_from_impls {
3820
3795
use super :: TryFromIntError ;
3821
3796
use convert:: TryFrom ;
3822
3797
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 ) ;
3829
3800
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 ) ;
3835
3801
rev ! ( try_from_lower_bounded, usize , i8 , i16 , i32 ) ;
3836
3802
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 ) ;
3842
3803
}
3843
3804
3844
3805
#[ cfg( target_pointer_width = "64" ) ]
3845
3806
mod ptr_try_from_impls {
3846
3807
use super :: TryFromIntError ;
3847
3808
use convert:: TryFrom ;
3848
3809
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 ) ;
3855
3812
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 ) ;
3861
3813
rev ! ( try_from_lower_bounded, usize , i8 , i16 , i32 , i64 ) ;
3862
3814
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 ) ;
3868
3815
}
3869
3816
3870
3817
#[ doc( hidden) ]
@@ -4074,6 +4021,20 @@ impl_from! { u32, i64, #[stable(feature = "lossless_int_conv", since = "1.5.0")]
4074
4021
impl_from ! { u32 , i128 , #[ stable( feature = "i128" , since = "1.26.0" ) ] }
4075
4022
impl_from ! { u64 , i128 , #[ stable( feature = "i128" , since = "1.26.0" ) ] }
4076
4023
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
+
4077
4038
// Note: integers can only be represented with full precision in a float if
4078
4039
// they fit in the significand, which is 24 bits in f32 and 53 bits in f64.
4079
4040
// Lossy float conversions are not implemented at this time.
0 commit comments