diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 0137275bc1589..be46e632be45f 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -85,6 +85,7 @@ #![feature(const_generic_impls_guard)] #![feature(const_generics)] #![feature(const_in_array_repeat_expressions)] +#![feature(const_if_match)] #![feature(cow_is_borrowed)] #![feature(dispatch_from_dyn)] #![feature(core_intrinsics)] diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs index ee75fc288fee5..3201c702abb29 100644 --- a/src/liballoc/raw_vec.rs +++ b/src/liballoc/raw_vec.rs @@ -52,15 +52,12 @@ impl RawVec { /// Like `new`, but parameterized over the choice of allocator for /// the returned `RawVec`. pub const fn new_in(a: A) -> Self { - // `!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::() == 0 { !0 } else { 0 }; + let cap = if mem::size_of::() == 0 { core::usize::MAX } 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::() == 0) as usize], + cap, a, } } @@ -132,19 +129,7 @@ impl RawVec { /// `RawVec` with capacity `usize::MAX`. Useful for implementing /// delayed allocation. pub const fn new() -> Self { - // FIXME(Centril): Reintegrate this with `fn new_in` when we can. - - // `!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::() == 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::() == 0) as usize], - a: Global, - } + Self::new_in(Global) } /// Creates a `RawVec` (on the system heap) with exactly the