remove a bit more hackery

This commit is contained in:
Mark Mansi 2019-11-25 15:29:57 -06:00
parent 17aa0cb2ca
commit 3ec3fca414
2 changed files with 9 additions and 41 deletions

View File

@ -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)]

View File

@ -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 @@ pub const fn new_in(a: A) -> Self {
}
}
/// 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