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

@ -9,6 +9,8 @@
test(attr(deny(warnings))) test(attr(deny(warnings)))
)] )]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(const_default_impls)]
#![feature(const_trait_impl)]
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![feature(if_let_guard)] #![feature(if_let_guard)]
#![feature(label_break_value)] #![feature(label_break_value)]

View file

@ -128,14 +128,7 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for P<T> {
impl<T> P<[T]> { impl<T> P<[T]> {
pub const fn new() -> P<[T]> { pub const fn new() -> P<[T]> {
// HACK(eddyb) bypass the lack of a `const fn` to create an empty `Box<[T]>` P { ptr: Box::default() }
// (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]>)
},
}
} }
#[inline(never)] #[inline(never)]