@@ -2154,7 +2154,7 @@ let bytes = ", $swap_op, stringify!($SelfT), ".to_be_bytes();
21542154assert_eq!(bytes, " , $be_bytes, ");
21552155```" ) ,
21562156 #[ stable( feature = "int_to_from_bytes" , since = "1.32.0" ) ]
2157- #[ rustc_const_unstable ( feature = "const_int_conversion" , issue = "53718 " ) ]
2157+ #[ rustc_const_stable ( feature = "const_int_conversion" , since = "1.43.0 " ) ]
21582158 #[ inline]
21592159 pub const fn to_be_bytes( self ) -> [ u8 ; mem:: size_of:: <Self >( ) ] {
21602160 self . to_be( ) . to_ne_bytes( )
@@ -2174,7 +2174,7 @@ let bytes = ", $swap_op, stringify!($SelfT), ".to_le_bytes();
21742174assert_eq!(bytes, " , $le_bytes, ");
21752175```" ) ,
21762176 #[ stable( feature = "int_to_from_bytes" , since = "1.32.0" ) ]
2177- #[ rustc_const_unstable ( feature = "const_int_conversion" , issue = "53718 " ) ]
2177+ #[ rustc_const_stable ( feature = "const_int_conversion" , since = "1.43.0 " ) ]
21782178 #[ inline]
21792179 pub const fn to_le_bytes( self ) -> [ u8 ; mem:: size_of:: <Self >( ) ] {
21802180 self . to_le( ) . to_ne_bytes( )
@@ -2209,12 +2209,20 @@ assert_eq!(
22092209);
22102210```" ) ,
22112211 #[ stable( feature = "int_to_from_bytes" , since = "1.32.0" ) ]
2212- #[ rustc_const_unstable( feature = "const_int_conversion" , issue = "53718" ) ]
2212+ #[ rustc_const_stable( feature = "const_int_conversion" , since = "1.43.0" ) ]
2213+ // SAFETY: const sound because integers are plain old datatypes so we can always
2214+ // transmute them to arrays of bytes
2215+ #[ allow_internal_unstable( const_fn_union) ]
22132216 #[ inline]
22142217 pub const fn to_ne_bytes( self ) -> [ u8 ; mem:: size_of:: <Self >( ) ] {
2218+ #[ repr( C ) ]
2219+ union Bytes {
2220+ val: $SelfT,
2221+ bytes: [ u8 ; mem:: size_of:: <$SelfT>( ) ] ,
2222+ }
22152223 // SAFETY: integers are plain old datatypes so we can always transmute them to
22162224 // arrays of bytes
2217- unsafe { mem :: transmute ( self ) }
2225+ unsafe { Bytes { val : self } . bytes }
22182226 }
22192227 }
22202228
@@ -2243,7 +2251,7 @@ fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT),
22432251}
22442252```" ) ,
22452253 #[ stable( feature = "int_to_from_bytes" , since = "1.32.0" ) ]
2246- #[ rustc_const_unstable ( feature = "const_int_conversion" , issue = "53718 " ) ]
2254+ #[ rustc_const_stable ( feature = "const_int_conversion" , since = "1.43.0 " ) ]
22472255 #[ inline]
22482256 pub const fn from_be_bytes( bytes: [ u8 ; mem:: size_of:: <Self >( ) ] ) -> Self {
22492257 Self :: from_be( Self :: from_ne_bytes( bytes) )
@@ -2276,7 +2284,7 @@ fn read_le_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT),
22762284}
22772285```" ) ,
22782286 #[ stable( feature = "int_to_from_bytes" , since = "1.32.0" ) ]
2279- #[ rustc_const_unstable ( feature = "const_int_conversion" , issue = "53718 " ) ]
2287+ #[ rustc_const_stable ( feature = "const_int_conversion" , since = "1.43.0 " ) ]
22802288 #[ inline]
22812289 pub const fn from_le_bytes( bytes: [ u8 ; mem:: size_of:: <Self >( ) ] ) -> Self {
22822290 Self :: from_le( Self :: from_ne_bytes( bytes) )
@@ -2319,11 +2327,19 @@ fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT),
23192327}
23202328```" ) ,
23212329 #[ stable( feature = "int_to_from_bytes" , since = "1.32.0" ) ]
2322- #[ rustc_const_unstable( feature = "const_int_conversion" , issue = "53718" ) ]
2330+ #[ rustc_const_stable( feature = "const_int_conversion" , since = "1.43.0" ) ]
2331+ // SAFETY: const sound because integers are plain old datatypes so we can always
2332+ // transmute to them
2333+ #[ allow_internal_unstable( const_fn_union) ]
23232334 #[ inline]
23242335 pub const fn from_ne_bytes( bytes: [ u8 ; mem:: size_of:: <Self >( ) ] ) -> Self {
2336+ #[ repr( C ) ]
2337+ union Bytes {
2338+ val: $SelfT,
2339+ bytes: [ u8 ; mem:: size_of:: <$SelfT>( ) ] ,
2340+ }
23252341 // SAFETY: integers are plain old datatypes so we can always transmute to them
2326- unsafe { mem :: transmute ( bytes) }
2342+ unsafe { Bytes { bytes } . val }
23272343 }
23282344 }
23292345
@@ -4099,7 +4115,7 @@ let bytes = ", $swap_op, stringify!($SelfT), ".to_be_bytes();
40994115assert_eq!(bytes, " , $be_bytes, ");
41004116```" ) ,
41014117 #[ stable( feature = "int_to_from_bytes" , since = "1.32.0" ) ]
4102- #[ rustc_const_unstable ( feature = "const_int_conversion" , issue = "53718 " ) ]
4118+ #[ rustc_const_stable ( feature = "const_int_conversion" , since = "1.43.0 " ) ]
41034119 #[ inline]
41044120 pub const fn to_be_bytes( self ) -> [ u8 ; mem:: size_of:: <Self >( ) ] {
41054121 self . to_be( ) . to_ne_bytes( )
@@ -4119,7 +4135,7 @@ let bytes = ", $swap_op, stringify!($SelfT), ".to_le_bytes();
41194135assert_eq!(bytes, " , $le_bytes, ");
41204136```" ) ,
41214137 #[ stable( feature = "int_to_from_bytes" , since = "1.32.0" ) ]
4122- #[ rustc_const_unstable ( feature = "const_int_conversion" , issue = "53718 " ) ]
4138+ #[ rustc_const_stable ( feature = "const_int_conversion" , since = "1.43.0 " ) ]
41234139 #[ inline]
41244140 pub const fn to_le_bytes( self ) -> [ u8 ; mem:: size_of:: <Self >( ) ] {
41254141 self . to_le( ) . to_ne_bytes( )
@@ -4154,12 +4170,20 @@ assert_eq!(
41544170);
41554171```" ) ,
41564172 #[ stable( feature = "int_to_from_bytes" , since = "1.32.0" ) ]
4157- #[ rustc_const_unstable( feature = "const_int_conversion" , issue = "53718" ) ]
4173+ #[ rustc_const_stable( feature = "const_int_conversion" , since = "1.43.0" ) ]
4174+ // SAFETY: const sound because integers are plain old datatypes so we can always
4175+ // transmute them to arrays of bytes
4176+ #[ allow_internal_unstable( const_fn_union) ]
41584177 #[ inline]
41594178 pub const fn to_ne_bytes( self ) -> [ u8 ; mem:: size_of:: <Self >( ) ] {
4179+ #[ repr( C ) ]
4180+ union Bytes {
4181+ val: $SelfT,
4182+ bytes: [ u8 ; mem:: size_of:: <$SelfT>( ) ] ,
4183+ }
41604184 // SAFETY: integers are plain old datatypes so we can always transmute them to
41614185 // arrays of bytes
4162- unsafe { mem :: transmute ( self ) }
4186+ unsafe { Bytes { val : self } . bytes }
41634187 }
41644188 }
41654189
@@ -4188,7 +4212,7 @@ fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT),
41884212}
41894213```" ) ,
41904214 #[ stable( feature = "int_to_from_bytes" , since = "1.32.0" ) ]
4191- #[ rustc_const_unstable ( feature = "const_int_conversion" , issue = "53718 " ) ]
4215+ #[ rustc_const_stable ( feature = "const_int_conversion" , since = "1.43.0 " ) ]
41924216 #[ inline]
41934217 pub const fn from_be_bytes( bytes: [ u8 ; mem:: size_of:: <Self >( ) ] ) -> Self {
41944218 Self :: from_be( Self :: from_ne_bytes( bytes) )
@@ -4221,7 +4245,7 @@ fn read_le_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT),
42214245}
42224246```" ) ,
42234247 #[ stable( feature = "int_to_from_bytes" , since = "1.32.0" ) ]
4224- #[ rustc_const_unstable ( feature = "const_int_conversion" , issue = "53718 " ) ]
4248+ #[ rustc_const_stable ( feature = "const_int_conversion" , since = "1.43.0 " ) ]
42254249 #[ inline]
42264250 pub const fn from_le_bytes( bytes: [ u8 ; mem:: size_of:: <Self >( ) ] ) -> Self {
42274251 Self :: from_le( Self :: from_ne_bytes( bytes) )
@@ -4264,11 +4288,19 @@ fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT),
42644288}
42654289```" ) ,
42664290 #[ stable( feature = "int_to_from_bytes" , since = "1.32.0" ) ]
4267- #[ rustc_const_unstable( feature = "const_int_conversion" , issue = "53718" ) ]
4291+ #[ rustc_const_stable( feature = "const_int_conversion" , since = "1.43.0" ) ]
4292+ // SAFETY: const sound because integers are plain old datatypes so we can always
4293+ // transmute to them
4294+ #[ allow_internal_unstable( const_fn_union) ]
42684295 #[ inline]
42694296 pub const fn from_ne_bytes( bytes: [ u8 ; mem:: size_of:: <Self >( ) ] ) -> Self {
4297+ #[ repr( C ) ]
4298+ union Bytes {
4299+ val: $SelfT,
4300+ bytes: [ u8 ; mem:: size_of:: <$SelfT>( ) ] ,
4301+ }
42704302 // SAFETY: integers are plain old datatypes so we can always transmute to them
4271- unsafe { mem :: transmute ( bytes) }
4303+ unsafe { Bytes { bytes } . val }
42724304 }
42734305 }
42744306
0 commit comments