From 3ec3fca414f62cb3172b9324fe7aaa516c71b4e9 Mon Sep 17 00:00:00 2001 From: Mark Mansi Date: Mon, 25 Nov 2019 15:29:57 -0600 Subject: remove a bit more hackery --- src/liballoc/lib.rs | 1 + src/liballoc/raw_vec.rs | 49 ++++++++----------------------------------------- 2 files changed, 9 insertions(+), 41 deletions(-) (limited to 'src/liballoc') diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 0137275bc15..6e44c7631b3 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -85,6 +85,7 @@ #![feature(const_generic_impls_guard)] #![feature(const_generics)] #![feature(const_in_array_repeat_expressions)] +#![cfg_attr(not(bootstrap), feature(const_if_match))] #![feature(cow_is_borrowed)] #![feature(dispatch_from_dyn)] #![feature(core_intrinsics)] diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs index dec990a117b..ce192a7450c 100644 --- a/src/liballoc/raw_vec.rs +++ b/src/liballoc/raw_vec.rs @@ -1,8 +1,6 @@ #![unstable(feature = "raw_vec_internals", reason = "implementation detail", issue = "0")] #![doc(hidden)] -#![feature(const_if_match)] - use core::cmp; use core::mem; use core::ops::Drop; @@ -53,9 +51,14 @@ pub struct RawVec { impl RawVec { /// Like `new`, but parameterized over the choice of allocator for /// the returned `RawVec`. - #[cfg(not(bootstrap))] pub const fn new_in(a: A) -> Self { - let cap = if mem::size_of::() == 0 { !0 } else { 0 }; + let cap = { + #[cfg(not(bootstrap))] + { if mem::size_of::() == 0 { !0 } else { 0 } } + + #[cfg(bootstrap)] + [0, !0][(mem::size_of::() == 0) as usize] + }; // `Unique::empty()` doubles as "unallocated" and "zero-sized allocation". RawVec { @@ -65,17 +68,6 @@ impl RawVec { } } - /// Like `new`, but parameterized over the choice of allocator for - /// the returned `RawVec`. - #[cfg(bootstrap)] - pub const fn new_in(a: A) -> Self { - RawVec { - ptr: Unique::empty(), - cap: [0, !0][(mem::size_of::() == 0) as usize], - a, - } - } - /// Like `with_capacity`, but parameterized over the choice of /// allocator for the returned `RawVec`. #[inline] @@ -142,33 +134,8 @@ impl RawVec { /// `RawVec` with capacity `0`. If `T` is zero-sized, then it makes a /// `RawVec` with capacity `usize::MAX`. Useful for implementing /// delayed allocation. - #[cfg(not(bootstrap))] - pub const fn new() -> Self { - // FIXME(Centril): Reintegrate this with `fn new_in` when we can. - - let cap = if mem::size_of::() == 0 { !0 } else { 0 }; - - // `Unique::empty()` doubles as "unallocated" and "zero-sized allocation". - RawVec { - ptr: Unique::empty(), - cap, - a: Global, - } - } - - /// Creates the biggest possible `RawVec` (on the system heap) - /// without allocating. If `T` has positive size, then this makes a - /// `RawVec` with capacity `0`. If `T` is zero-sized, then it makes a - /// `RawVec` with capacity `usize::MAX`. Useful for implementing - /// delayed allocation. - #[cfg(bootstrap)] pub const fn new() -> Self { - // `Unique::empty()` doubles as "unallocated" and "zero-sized allocation". - RawVec { - ptr: Unique::empty(), - cap: [0, !0][(mem::size_of::() == 0) as usize], - a: Global, - } + Self::new_in(Global) } /// Creates a `RawVec` (on the system heap) with exactly the -- cgit 1.4.1-3-g733a5