@@ -113,13 +113,38 @@ impl<T, A: Alloc> RawVec<T, A> {
113
113
}
114
114
115
115
impl < T > RawVec < T , Global > {
116
+ /// HACK(Centril): This exists because `#[unstable]` `const fn`s needn't conform
117
+ /// to `min_const_fn` and so they cannot be called in `min_const_fn`s either.
118
+ ///
119
+ /// If you change `RawVec<T>::new` or dependencies, please take care to not
120
+ /// introduce anything that would truly violate `min_const_fn`.
121
+ ///
122
+ /// NOTE: We could avoid this hack and check conformance with some
123
+ /// `#[rustc_force_min_const_fn]` attribute which requires conformance
124
+ /// with `min_const_fn` but does not necessarily allow calling it in
125
+ /// `stable(...) const fn` / user code not enabling `foo` when
126
+ /// `#[rustc_const_unstable(feature = "foo", ..)]` is present.
127
+ pub const NEW : Self = Self :: new ( ) ;
128
+
116
129
/// Creates the biggest possible `RawVec` (on the system heap)
117
130
/// without allocating. If `T` has positive size, then this makes a
118
131
/// `RawVec` with capacity `0`. If `T` is zero-sized, then it makes a
119
132
/// `RawVec` with capacity `usize::MAX`. Useful for implementing
120
133
/// delayed allocation.
121
134
pub const fn new ( ) -> Self {
122
- Self :: new_in ( Global )
135
+ // FIXME(Centril): Reintegrate this with `fn new_in` when we can.
136
+
137
+ // `!0` is `usize::MAX`. This branch should be stripped at compile time.
138
+ // FIXME(mark-i-m): use this line when `if`s are allowed in `const`:
139
+ //let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
140
+
141
+ // `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
142
+ RawVec {
143
+ ptr : Unique :: empty ( ) ,
144
+ // FIXME(mark-i-m): use `cap` when ifs are allowed in const
145
+ cap : [ 0 , !0 ] [ ( mem:: size_of :: < T > ( ) == 0 ) as usize ] ,
146
+ a : Global ,
147
+ }
123
148
}
124
149
125
150
/// Creates a `RawVec` (on the system heap) with exactly the
0 commit comments