assert_eq!(bytes, ", $be_bytes, ");
```"),
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
- #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+ #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
#[inline]
pub const fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] {
self.to_be().to_ne_bytes()
assert_eq!(bytes, ", $le_bytes, ");
```"),
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
- #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+ #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
#[inline]
pub const fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] {
self.to_le().to_ne_bytes()
);
```"),
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
- #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+ #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
+ // SAFETY: const sound because integers are plain old datatypes so we can always
+ // transmute them to arrays of bytes
+ #[allow_internal_unstable(const_fn_union)]
#[inline]
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
+ #[repr(C)]
+ union Bytes {
+ val: $SelfT,
+ bytes: [u8; mem::size_of::<$SelfT>()],
+ }
// SAFETY: integers are plain old datatypes so we can always transmute them to
// arrays of bytes
- unsafe { mem::transmute(self) }
+ unsafe { Bytes { val: self }.bytes }
}
}
}
```"),
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
- #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+ #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
#[inline]
pub const fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
Self::from_be(Self::from_ne_bytes(bytes))
}
```"),
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
- #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+ #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
#[inline]
pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
Self::from_le(Self::from_ne_bytes(bytes))
}
```"),
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
- #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+ #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
+ // SAFETY: const sound because integers are plain old datatypes so we can always
+ // transmute to them
+ #[allow_internal_unstable(const_fn_union)]
#[inline]
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
+ #[repr(C)]
+ union Bytes {
+ val: $SelfT,
+ bytes: [u8; mem::size_of::<$SelfT>()],
+ }
// SAFETY: integers are plain old datatypes so we can always transmute to them
- unsafe { mem::transmute(bytes) }
+ unsafe { Bytes { bytes }.val }
}
}
assert_eq!(bytes, ", $be_bytes, ");
```"),
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
- #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+ #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
#[inline]
pub const fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] {
self.to_be().to_ne_bytes()
assert_eq!(bytes, ", $le_bytes, ");
```"),
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
- #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+ #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
#[inline]
pub const fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] {
self.to_le().to_ne_bytes()
);
```"),
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
- #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+ #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
+ // SAFETY: const sound because integers are plain old datatypes so we can always
+ // transmute them to arrays of bytes
+ #[allow_internal_unstable(const_fn_union)]
#[inline]
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
+ #[repr(C)]
+ union Bytes {
+ val: $SelfT,
+ bytes: [u8; mem::size_of::<$SelfT>()],
+ }
// SAFETY: integers are plain old datatypes so we can always transmute them to
// arrays of bytes
- unsafe { mem::transmute(self) }
+ unsafe { Bytes { val: self }.bytes }
}
}
}
```"),
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
- #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+ #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
#[inline]
pub const fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
Self::from_be(Self::from_ne_bytes(bytes))
}
```"),
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
- #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+ #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
#[inline]
pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
Self::from_le(Self::from_ne_bytes(bytes))
}
```"),
#[stable(feature = "int_to_from_bytes", since = "1.32.0")]
- #[rustc_const_unstable(feature = "const_int_conversion", issue = "53718")]
+ #[rustc_const_stable(feature = "const_int_conversion", since = "1.43.0")]
+ // SAFETY: const sound because integers are plain old datatypes so we can always
+ // transmute to them
+ #[allow_internal_unstable(const_fn_union)]
#[inline]
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
+ #[repr(C)]
+ union Bytes {
+ val: $SelfT,
+ bytes: [u8; mem::size_of::<$SelfT>()],
+ }
// SAFETY: integers are plain old datatypes so we can always transmute to them
- unsafe { mem::transmute(bytes) }
+ unsafe { Bytes { bytes }.val }
}
}