@@ -2154,7 +2154,7 @@ let bytes = ", $swap_op, stringify!($SelfT), ".to_be_bytes();
2154
2154
assert_eq!(bytes, " , $be_bytes, ");
2155
2155
```" ) ,
2156
2156
#[ 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 " ) ]
2158
2158
#[ inline]
2159
2159
pub const fn to_be_bytes( self ) -> [ u8 ; mem:: size_of:: <Self >( ) ] {
2160
2160
self . to_be( ) . to_ne_bytes( )
@@ -2174,7 +2174,7 @@ let bytes = ", $swap_op, stringify!($SelfT), ".to_le_bytes();
2174
2174
assert_eq!(bytes, " , $le_bytes, ");
2175
2175
```" ) ,
2176
2176
#[ 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 " ) ]
2178
2178
#[ inline]
2179
2179
pub const fn to_le_bytes( self ) -> [ u8 ; mem:: size_of:: <Self >( ) ] {
2180
2180
self . to_le( ) . to_ne_bytes( )
@@ -2209,12 +2209,20 @@ assert_eq!(
2209
2209
);
2210
2210
```" ) ,
2211
2211
#[ 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) ]
2213
2216
#[ inline]
2214
2217
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
+ }
2215
2223
// SAFETY: integers are plain old datatypes so we can always transmute them to
2216
2224
// arrays of bytes
2217
- unsafe { mem :: transmute ( self ) }
2225
+ unsafe { Bytes { val : self } . bytes }
2218
2226
}
2219
2227
}
2220
2228
@@ -2243,7 +2251,7 @@ fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT),
2243
2251
}
2244
2252
```" ) ,
2245
2253
#[ 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 " ) ]
2247
2255
#[ inline]
2248
2256
pub const fn from_be_bytes( bytes: [ u8 ; mem:: size_of:: <Self >( ) ] ) -> Self {
2249
2257
Self :: from_be( Self :: from_ne_bytes( bytes) )
@@ -2276,7 +2284,7 @@ fn read_le_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT),
2276
2284
}
2277
2285
```" ) ,
2278
2286
#[ 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 " ) ]
2280
2288
#[ inline]
2281
2289
pub const fn from_le_bytes( bytes: [ u8 ; mem:: size_of:: <Self >( ) ] ) -> Self {
2282
2290
Self :: from_le( Self :: from_ne_bytes( bytes) )
@@ -2319,11 +2327,19 @@ fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT),
2319
2327
}
2320
2328
```" ) ,
2321
2329
#[ 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) ]
2323
2334
#[ inline]
2324
2335
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
+ }
2325
2341
// SAFETY: integers are plain old datatypes so we can always transmute to them
2326
- unsafe { mem :: transmute ( bytes) }
2342
+ unsafe { Bytes { bytes } . val }
2327
2343
}
2328
2344
}
2329
2345
@@ -4099,7 +4115,7 @@ let bytes = ", $swap_op, stringify!($SelfT), ".to_be_bytes();
4099
4115
assert_eq!(bytes, " , $be_bytes, ");
4100
4116
```" ) ,
4101
4117
#[ 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 " ) ]
4103
4119
#[ inline]
4104
4120
pub const fn to_be_bytes( self ) -> [ u8 ; mem:: size_of:: <Self >( ) ] {
4105
4121
self . to_be( ) . to_ne_bytes( )
@@ -4119,7 +4135,7 @@ let bytes = ", $swap_op, stringify!($SelfT), ".to_le_bytes();
4119
4135
assert_eq!(bytes, " , $le_bytes, ");
4120
4136
```" ) ,
4121
4137
#[ 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 " ) ]
4123
4139
#[ inline]
4124
4140
pub const fn to_le_bytes( self ) -> [ u8 ; mem:: size_of:: <Self >( ) ] {
4125
4141
self . to_le( ) . to_ne_bytes( )
@@ -4154,12 +4170,20 @@ assert_eq!(
4154
4170
);
4155
4171
```" ) ,
4156
4172
#[ 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) ]
4158
4177
#[ inline]
4159
4178
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
+ }
4160
4184
// SAFETY: integers are plain old datatypes so we can always transmute them to
4161
4185
// arrays of bytes
4162
- unsafe { mem :: transmute ( self ) }
4186
+ unsafe { Bytes { val : self } . bytes }
4163
4187
}
4164
4188
}
4165
4189
@@ -4188,7 +4212,7 @@ fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT),
4188
4212
}
4189
4213
```" ) ,
4190
4214
#[ 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 " ) ]
4192
4216
#[ inline]
4193
4217
pub const fn from_be_bytes( bytes: [ u8 ; mem:: size_of:: <Self >( ) ] ) -> Self {
4194
4218
Self :: from_be( Self :: from_ne_bytes( bytes) )
@@ -4221,7 +4245,7 @@ fn read_le_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT),
4221
4245
}
4222
4246
```" ) ,
4223
4247
#[ 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 " ) ]
4225
4249
#[ inline]
4226
4250
pub const fn from_le_bytes( bytes: [ u8 ; mem:: size_of:: <Self >( ) ] ) -> Self {
4227
4251
Self :: from_le( Self :: from_ne_bytes( bytes) )
@@ -4264,11 +4288,19 @@ fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT),
4264
4288
}
4265
4289
```" ) ,
4266
4290
#[ 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) ]
4268
4295
#[ inline]
4269
4296
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
+ }
4270
4302
// SAFETY: integers are plain old datatypes so we can always transmute to them
4271
- unsafe { mem :: transmute ( bytes) }
4303
+ unsafe { Bytes { bytes } . val }
4272
4304
}
4273
4305
}
4274
4306
0 commit comments