Skip to content

Commit 2d5eda8

Browse files
committed
Use const Box::default in P::<[T]>::new
1 parent a2902eb commit 2d5eda8

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

compiler/rustc_ast/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
test(attr(deny(warnings)))
1010
)]
1111
#![feature(box_patterns)]
12+
#![feature(const_default_impls)]
13+
#![feature(const_trait_impl)]
1214
#![feature(crate_visibility_modifier)]
1315
#![feature(if_let_guard)]
1416
#![feature(label_break_value)]

compiler/rustc_ast/src/ptr.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,7 @@ impl<S: Encoder, T: Encodable<S>> Encodable<S> for P<T> {
128128

129129
impl<T> P<[T]> {
130130
pub const fn new() -> P<[T]> {
131-
// HACK(eddyb) bypass the lack of a `const fn` to create an empty `Box<[T]>`
132-
// (as trait methods, `default` in this case, can't be `const fn` yet).
133-
P {
134-
ptr: unsafe {
135-
use std::ptr::NonNull;
136-
std::mem::transmute(NonNull::<[T; 0]>::dangling() as NonNull<[T]>)
137-
},
138-
}
131+
P { ptr: Box::default() }
139132
}
140133

141134
#[inline(never)]

0 commit comments

Comments
 (0)