@@ -54,28 +54,18 @@ pub struct RawVec<T, A: Alloc = Global> {
54
54
}
55
55
56
56
impl < T , A : Alloc > RawVec < T , A > {
57
- // FIXME: this should be made `const` when `if` statements are allowed
58
57
/// Like `new` but parameterized over the choice of allocator for
59
58
/// the returned RawVec.
60
- pub fn new_in ( a : A ) -> Self {
59
+ pub const fn new_in ( a : A ) -> Self {
61
60
// !0 is usize::MAX. This branch should be stripped at compile time.
62
- let cap = if mem:: size_of :: < T > ( ) == 0 { !0 } else { 0 } ;
61
+ // FIXME(mark-i-m): use this line when `if`s are allowed in `const`
62
+ //let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
63
63
64
64
// Unique::empty() doubles as "unallocated" and "zero-sized allocation"
65
65
RawVec {
66
66
ptr : Unique :: empty ( ) ,
67
- cap,
68
- a,
69
- }
70
- }
71
-
72
- // FIXME: this should removed when `new_in` can be made `const`
73
- /// Like `empty` but parametrized over the choice of allocator for the returned `RawVec`.
74
- pub const fn empty_in ( a : A ) -> Self {
75
- // Unique::empty() doubles as "unallocated" and "zero-sized allocation"
76
- RawVec {
77
- ptr : Unique :: empty ( ) ,
78
- cap : 0 ,
67
+ // FIXME(mark-i-m): use `cap` when ifs are allowed in const
68
+ cap : [ 0 , !0 ] [ ( mem:: size_of :: < T > ( ) != 0 ) as usize ] ,
79
69
a,
80
70
}
81
71
}
@@ -132,17 +122,10 @@ impl<T> RawVec<T, Global> {
132
122
/// RawVec with capacity 0. If T has 0 size, then it makes a
133
123
/// RawVec with capacity `usize::MAX`. Useful for implementing
134
124
/// delayed allocation.
135
- pub fn new ( ) -> Self {
125
+ pub const fn new ( ) -> Self {
136
126
Self :: new_in ( Global )
137
127
}
138
128
139
- // FIXME: this should removed when `new` can be made `const`
140
- /// Create a `RawVec` with capcity 0 (on the system heap), regardless of `T`, without
141
- /// allocating.
142
- pub const fn empty ( ) -> Self {
143
- Self :: empty_in ( Global )
144
- }
145
-
146
129
/// Creates a RawVec (on the system heap) with exactly the
147
130
/// capacity and alignment requirements for a `[T; cap]`. This is
148
131
/// equivalent to calling RawVec::new when `cap` is 0 or T is
0 commit comments