Rollup merge of #73459 - cuviper:into_boxed_slice-unicast, r=dtolnay

Reduce pointer casts in Box::into_boxed_slice

We only need to cast the pointer once to change `Box<T>` to an array
`Box<[T; 1]>`, then we can let unsized coercion return `Box<[T]>`.
This commit is contained in:
Ralf Jung 2020-06-19 08:56:15 +02:00 committed by GitHub
commit fc2ce7cfef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -248,7 +248,7 @@ pub fn pin(x: T) -> Pin<Box<T>> {
#[unstable(feature = "box_into_boxed_slice", issue = "71582")]
pub fn into_boxed_slice(boxed: Box<T>) -> Box<[T]> {
// *mut T and *mut [T; 1] have the same size and alignment
unsafe { Box::from_raw(Box::into_raw(boxed) as *mut [T; 1] as *mut [T]) }
unsafe { Box::from_raw(Box::into_raw(boxed) as *mut [T; 1]) }
}
}