From 17aa0cb2ca73ad789e718bf9162a740af02a829f Mon Sep 17 00:00:00 2001
From: Mark Mansi <markm@cs.wisc.edu>
Date: Mon, 25 Nov 2019 14:44:19 -0600
Subject: [PATCH 1/6] Remove a const-if-hack in RawVec

---
 src/liballoc/raw_vec.rs | 40 ++++++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs
index ee75fc288fee5..dec990a117bf8 100644
--- a/src/liballoc/raw_vec.rs
+++ b/src/liballoc/raw_vec.rs
@@ -1,6 +1,8 @@
 #![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;
@@ -51,15 +53,24 @@ 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 {
-        // `!0` is `usize::MAX`. This branch should be stripped at compile time.
-        // FIXME(mark-i-m): use this line when `if`s are allowed in `const`:
-        //let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
+        let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
 
         // `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
         RawVec {
             ptr: Unique::empty(),
-            // FIXME(mark-i-m): use `cap` when ifs are allowed in const
+            cap,
+            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,
         }
@@ -131,17 +142,30 @@ 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.
 
-        // `!0` is `usize::MAX`. This branch should be stripped at compile time.
-        // FIXME(mark-i-m): use this line when `if`s are allowed in `const`:
-        //let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
+        let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
 
         // `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
         RawVec {
             ptr: Unique::empty(),
-            // FIXME(mark-i-m): use `cap` when ifs are allowed in const
+            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,
         }

From 3ec3fca414f62cb3172b9324fe7aaa516c71b4e9 Mon Sep 17 00:00:00 2001
From: Mark Mansi <markm@cs.wisc.edu>
Date: Mon, 25 Nov 2019 15:29:57 -0600
Subject: [PATCH 2/6] remove a bit more hackery

---
 src/liballoc/lib.rs     |  1 +
 src/liballoc/raw_vec.rs | 49 +++++++----------------------------------
 2 files changed, 9 insertions(+), 41 deletions(-)

diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs
index 0137275bc1589..6e44c7631b3f0 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 dec990a117bf8..ce192a7450c9d 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

From baaf864e07a8b8b99ed548c08606c1c7da74256b Mon Sep 17 00:00:00 2001
From: Mark Mansi <markm@cs.wisc.edu>
Date: Mon, 25 Nov 2019 18:14:46 -0600
Subject: [PATCH 3/6] use usize::MAX instead of !0

---
 src/liballoc/raw_vec.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs
index ce192a7450c9d..0d6fb25957432 100644
--- a/src/liballoc/raw_vec.rs
+++ b/src/liballoc/raw_vec.rs
@@ -54,7 +54,7 @@ impl<T, A: Alloc> RawVec<T, A> {
     pub const fn new_in(a: A) -> Self {
         let cap = {
             #[cfg(not(bootstrap))]
-            { if mem::size_of::<T>() == 0 { !0 } else { 0 } }
+            { if mem::size_of::<T>() == 0 { usize::MAX } else { 0 } }
 
             #[cfg(bootstrap)]
             [0, !0][(mem::size_of::<T>() == 0) as usize]

From 951f041347529e504b132640d829914a0f7ef7c6 Mon Sep 17 00:00:00 2001
From: Mark Mansi <markm@cs.wisc.edu>
Date: Tue, 26 Nov 2019 11:03:53 -0600
Subject: [PATCH 4/6] fix import

---
 src/liballoc/raw_vec.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs
index 0d6fb25957432..dff8364b84730 100644
--- a/src/liballoc/raw_vec.rs
+++ b/src/liballoc/raw_vec.rs
@@ -54,7 +54,7 @@ impl<T, A: Alloc> RawVec<T, A> {
     pub const fn new_in(a: A) -> Self {
         let cap = {
             #[cfg(not(bootstrap))]
-            { if mem::size_of::<T>() == 0 { usize::MAX } else { 0 } }
+            { if mem::size_of::<T>() == 0 { core::usize::MAX } else { 0 } }
 
             #[cfg(bootstrap)]
             [0, !0][(mem::size_of::<T>() == 0) as usize]

From 253543560aa10f90607b23b5b12be3cfe28fdb1b Mon Sep 17 00:00:00 2001
From: Mark Mansi <markm@cs.wisc.edu>
Date: Tue, 26 Nov 2019 11:06:53 -0600
Subject: [PATCH 5/6] add fixme

---
 src/liballoc/raw_vec.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs
index dff8364b84730..96de5185b88cd 100644
--- a/src/liballoc/raw_vec.rs
+++ b/src/liballoc/raw_vec.rs
@@ -52,6 +52,7 @@ impl<T, A: Alloc> RawVec<T, A> {
     /// Like `new`, but parameterized over the choice of allocator for
     /// the returned `RawVec`.
     pub const fn new_in(a: A) -> Self {
+        // FIXME(mark-i-m): remove bootstrapping cfgs these after a cycle
         let cap = {
             #[cfg(not(bootstrap))]
             { if mem::size_of::<T>() == 0 { core::usize::MAX } else { 0 } }

From 7d268119f07aeb41a1abe093c3fd2434743ac228 Mon Sep 17 00:00:00 2001
From: Mark Mansi <markm@cs.wisc.edu>
Date: Wed, 18 Dec 2019 12:04:47 -0600
Subject: [PATCH 6/6] no need to bootstrap

---
 src/liballoc/lib.rs     | 2 +-
 src/liballoc/raw_vec.rs | 9 +--------
 2 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs
index 6e44c7631b3f0..be46e632be45f 100644
--- a/src/liballoc/lib.rs
+++ b/src/liballoc/lib.rs
@@ -85,7 +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(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 96de5185b88cd..3201c702abb29 100644
--- a/src/liballoc/raw_vec.rs
+++ b/src/liballoc/raw_vec.rs
@@ -52,14 +52,7 @@ impl<T, A: Alloc> RawVec<T, A> {
     /// Like `new`, but parameterized over the choice of allocator for
     /// the returned `RawVec`.
     pub const fn new_in(a: A) -> Self {
-        // FIXME(mark-i-m): remove bootstrapping cfgs these after a cycle
-        let cap = {
-            #[cfg(not(bootstrap))]
-            { if mem::size_of::<T>() == 0 { core::usize::MAX } else { 0 } }
-
-            #[cfg(bootstrap)]
-            [0, !0][(mem::size_of::<T>() == 0) as usize]
-        };
+        let cap = if mem::size_of::<T>() == 0 { core::usize::MAX } else { 0 };
 
         // `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
         RawVec {