Constify mem::transmute_copy

This commit is contained in:
Albin Hedman 2021-03-13 20:43:47 +01:00
parent 45988ee438
commit db9a53b5d7
No known key found for this signature in database
GPG Key ID: 1F501ECD1BBD70A7

View File

@ -933,7 +933,8 @@ pub fn drop<T>(_x: T) {}
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
#[rustc_const_unstable(feature = "const_transmute_copy", issue = "83165")]
pub const unsafe fn transmute_copy<T, U>(src: &T) -> U {
// If U has a higher alignment requirement, src may not be suitably aligned.
if align_of::<U>() > align_of::<T>() {
// SAFETY: `src` is a reference which is guaranteed to be valid for reads.