1
Fork 0

Use const Box::default in P::<[T]>::new

This commit is contained in:
Josh Stone 2022-04-11 11:44:13 -07:00
parent a2902ebe57
commit 2d5eda8fb0
2 changed files with 3 additions and 8 deletions

View file

@ -128,14 +128,7 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for P<T> {
impl<T> P<[T]> {
pub const fn new() -> P<[T]> {
// HACK(eddyb) bypass the lack of a `const fn` to create an empty `Box<[T]>`
// (as trait methods, `default` in this case, can't be `const fn` yet).
P {
ptr: unsafe {
use std::ptr::NonNull;
std::mem::transmute(NonNull::<[T; 0]>::dangling() as NonNull<[T]>)
},
}
P { ptr: Box::default() }
}
#[inline(never)]