about summary refs log tree commit diff
path: root/src/liballoc/raw_vec.rs
diff options
context:
space:
mode:
authorMark Mansi <markm@cs.wisc.edu>2019-11-25 15:29:57 -0600
committerMark Mansi <markm@cs.wisc.edu>2019-12-18 20:19:05 -0600
commit3ec3fca414f62cb3172b9324fe7aaa516c71b4e9 (patch)
treec5d84ca17b53165ee25260e3917585f13cf94786 /src/liballoc/raw_vec.rs
parent17aa0cb2ca73ad789e718bf9162a740af02a829f (diff)
downloadrust-3ec3fca414f62cb3172b9324fe7aaa516c71b4e9.tar.gz
rust-3ec3fca414f62cb3172b9324fe7aaa516c71b4e9.zip
remove a bit more hackery
Diffstat (limited to 'src/liballoc/raw_vec.rs')
-rw-r--r--src/liballoc/raw_vec.rs49
1 files changed, 8 insertions, 41 deletions
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<T, A: Alloc = Global> {
 impl<T, A: Alloc> RawVec<T, A> {
     /// 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::<T>() == 0 { !0 } else { 0 };
+        let cap = {
+            #[cfg(not(bootstrap))]
+            { if mem::size_of::<T>() == 0 { !0 } else { 0 } }
+
+            #[cfg(bootstrap)]
+            [0, !0][(mem::size_of::<T>() == 0) as usize]
+        };
 
         // `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
         RawVec {
@@ -65,17 +68,6 @@ impl<T, A: Alloc> RawVec<T, A> {
         }
     }
 
-    /// 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::<T>() == 0) as usize],
-            a,
-        }
-    }
-
     /// Like `with_capacity`, but parameterized over the choice of
     /// allocator for the returned `RawVec`.
     #[inline]
@@ -142,33 +134,8 @@ impl<T> RawVec<T, Global> {
     /// `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::<T>() == 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::<T>() == 0) as usize],
-            a: Global,
-        }
+        Self::new_in(Global)
     }
 
     /// Creates a `RawVec` (on the system heap) with exactly the