Skip to content

Commit 3ec3fca

Browse files
committed
remove a bit more hackery
1 parent 17aa0cb commit 3ec3fca

File tree

2 files changed

+9
-41
lines changed

2 files changed

+9
-41
lines changed

src/liballoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#![feature(const_generic_impls_guard)]
8686
#![feature(const_generics)]
8787
#![feature(const_in_array_repeat_expressions)]
88+
#![cfg_attr(not(bootstrap), feature(const_if_match))]
8889
#![feature(cow_is_borrowed)]
8990
#![feature(dispatch_from_dyn)]
9091
#![feature(core_intrinsics)]

src/liballoc/raw_vec.rs

+8-41
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#![unstable(feature = "raw_vec_internals", reason = "implementation detail", issue = "0")]
22
#![doc(hidden)]
33

4-
#![feature(const_if_match)]
5-
64
use core::cmp;
75
use core::mem;
86
use core::ops::Drop;
@@ -53,9 +51,14 @@ pub struct RawVec<T, A: Alloc = Global> {
5351
impl<T, A: Alloc> RawVec<T, A> {
5452
/// Like `new`, but parameterized over the choice of allocator for
5553
/// the returned `RawVec`.
56-
#[cfg(not(bootstrap))]
5754
pub const fn new_in(a: A) -> Self {
58-
let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
55+
let cap = {
56+
#[cfg(not(bootstrap))]
57+
{ if mem::size_of::<T>() == 0 { !0 } else { 0 } }
58+
59+
#[cfg(bootstrap)]
60+
[0, !0][(mem::size_of::<T>() == 0) as usize]
61+
};
5962

6063
// `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
6164
RawVec {
@@ -65,17 +68,6 @@ impl<T, A: Alloc> RawVec<T, A> {
6568
}
6669
}
6770

68-
/// Like `new`, but parameterized over the choice of allocator for
69-
/// the returned `RawVec`.
70-
#[cfg(bootstrap)]
71-
pub const fn new_in(a: A) -> Self {
72-
RawVec {
73-
ptr: Unique::empty(),
74-
cap: [0, !0][(mem::size_of::<T>() == 0) as usize],
75-
a,
76-
}
77-
}
78-
7971
/// Like `with_capacity`, but parameterized over the choice of
8072
/// allocator for the returned `RawVec`.
8173
#[inline]
@@ -142,33 +134,8 @@ impl<T> RawVec<T, Global> {
142134
/// `RawVec` with capacity `0`. If `T` is zero-sized, then it makes a
143135
/// `RawVec` with capacity `usize::MAX`. Useful for implementing
144136
/// delayed allocation.
145-
#[cfg(not(bootstrap))]
146-
pub const fn new() -> Self {
147-
// FIXME(Centril): Reintegrate this with `fn new_in` when we can.
148-
149-
let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
150-
151-
// `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
152-
RawVec {
153-
ptr: Unique::empty(),
154-
cap,
155-
a: Global,
156-
}
157-
}
158-
159-
/// Creates the biggest possible `RawVec` (on the system heap)
160-
/// without allocating. If `T` has positive size, then this makes a
161-
/// `RawVec` with capacity `0`. If `T` is zero-sized, then it makes a
162-
/// `RawVec` with capacity `usize::MAX`. Useful for implementing
163-
/// delayed allocation.
164-
#[cfg(bootstrap)]
165137
pub const fn new() -> Self {
166-
// `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
167-
RawVec {
168-
ptr: Unique::empty(),
169-
cap: [0, !0][(mem::size_of::<T>() == 0) as usize],
170-
a: Global,
171-
}
138+
Self::new_in(Global)
172139
}
173140

174141
/// Creates a `RawVec` (on the system heap) with exactly the

0 commit comments

Comments
 (0)