11#![ unstable( feature = "raw_vec_internals" , reason = "implementation detail" , issue = "0" ) ]
22#![ doc( hidden) ]
33
4- #![ feature( const_if_match) ]
5-
64use core:: cmp;
75use core:: mem;
86use core:: ops:: Drop ;
@@ -53,9 +51,14 @@ pub struct RawVec<T, A: Alloc = Global> {
5351impl < 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