diff options
Diffstat (limited to 'src/libsyntax/ptr.rs')
| -rw-r--r-- | src/libsyntax/ptr.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/libsyntax/ptr.rs b/src/libsyntax/ptr.rs index d577243fb3d..f0cfa5a84a8 100644 --- a/src/libsyntax/ptr.rs +++ b/src/libsyntax/ptr.rs @@ -133,8 +133,15 @@ impl<T: Encodable> Encodable for P<T> { } impl<T> P<[T]> { - pub fn new() -> P<[T]> { - P { ptr: Default::default() } + 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]>) + }, + } } #[inline(never)] |
