Rollup merge of #66755 - mark-i-m:const-vec-new, r=ecstatic-morse
Remove a const-if-hack in RawVec r? @ecstatic-morse cc @Centril
This commit is contained in:
commit
57da9d3269
|
@ -85,6 +85,7 @@
|
||||||
#![feature(const_generic_impls_guard)]
|
#![feature(const_generic_impls_guard)]
|
||||||
#![feature(const_generics)]
|
#![feature(const_generics)]
|
||||||
#![feature(const_in_array_repeat_expressions)]
|
#![feature(const_in_array_repeat_expressions)]
|
||||||
|
#![feature(const_if_match)]
|
||||||
#![feature(cow_is_borrowed)]
|
#![feature(cow_is_borrowed)]
|
||||||
#![feature(dispatch_from_dyn)]
|
#![feature(dispatch_from_dyn)]
|
||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics)]
|
||||||
|
|
|
@ -52,15 +52,12 @@ impl<T, A: Alloc> RawVec<T, A> {
|
||||||
/// Like `new`, but parameterized over the choice of allocator for
|
/// Like `new`, but parameterized over the choice of allocator for
|
||||||
/// the returned `RawVec`.
|
/// the returned `RawVec`.
|
||||||
pub const fn new_in(a: A) -> Self {
|
pub const fn new_in(a: A) -> Self {
|
||||||
// `!0` is `usize::MAX`. This branch should be stripped at compile time.
|
let cap = if mem::size_of::<T>() == 0 { core::usize::MAX } else { 0 };
|
||||||
// FIXME(mark-i-m): use this line when `if`s are allowed in `const`:
|
|
||||||
//let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
|
|
||||||
|
|
||||||
// `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
|
// `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
|
||||||
RawVec {
|
RawVec {
|
||||||
ptr: Unique::empty(),
|
ptr: Unique::empty(),
|
||||||
// FIXME(mark-i-m): use `cap` when ifs are allowed in const
|
cap,
|
||||||
cap: [0, !0][(mem::size_of::<T>() == 0) as usize],
|
|
||||||
a,
|
a,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,19 +129,7 @@ impl<T> RawVec<T, Global> {
|
||||||
/// `RawVec` with capacity `usize::MAX`. Useful for implementing
|
/// `RawVec` with capacity `usize::MAX`. Useful for implementing
|
||||||
/// delayed allocation.
|
/// delayed allocation.
|
||||||
pub const fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
// FIXME(Centril): Reintegrate this with `fn new_in` when we can.
|
Self::new_in(Global)
|
||||||
|
|
||||||
// `!0` is `usize::MAX`. This branch should be stripped at compile time.
|
|
||||||
// FIXME(mark-i-m): use this line when `if`s are allowed in `const`:
|
|
||||||
//let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 };
|
|
||||||
|
|
||||||
// `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
|
|
||||||
RawVec {
|
|
||||||
ptr: Unique::empty(),
|
|
||||||
// FIXME(mark-i-m): use `cap` when ifs are allowed in const
|
|
||||||
cap: [0, !0][(mem::size_of::<T>() == 0) as usize],
|
|
||||||
a: Global,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a `RawVec` (on the system heap) with exactly the
|
/// Creates a `RawVec` (on the system heap) with exactly the
|
||||||
|
|
Loading…
Reference in New Issue