From a7c2cf8f510788040c4a8a721582a3533d0bf35a Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 17 Jun 2020 16:30:27 -0700 Subject: [PATCH] Reduce pointer casts in Box::into_boxed_slice We only need to cast the pointer once to change `Box` to an array `Box<[T; 1]>`, then we can let unsized coercion return `Box<[T]>`. --- src/liballoc/boxed.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 22c344323a2ed..ab0dde0ada660 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -248,7 +248,7 @@ impl Box { #[unstable(feature = "box_into_boxed_slice", issue = "71582")] pub fn into_boxed_slice(boxed: Box) -> 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]) } } }