Skip to content

Commit c1fa023

Browse files
committed
Fix ZST handling for RawVec
1 parent d9d35cc commit c1fa023

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/liballoc/raw_vec.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,14 +483,14 @@ impl<T, A: AllocRef> RawVec<T, A> {
483483
placement: ReallocPlacement,
484484
init: AllocInit,
485485
) -> Result<(), TryReserveError> {
486+
let elem_size = mem::size_of::<T>();
487+
if elem_size == 0 {
488+
// Since we return a capacity of `usize::MAX` when `elem_size` is
489+
// 0, getting to here necessarily means the `RawVec` is overfull.
490+
return Err(CapacityOverflow);
491+
}
486492
let layout = match strategy {
487493
Double => unsafe {
488-
let elem_size = mem::size_of::<T>();
489-
if elem_size == 0 {
490-
// Since we return a capacity of `usize::MAX` when `elem_size` is
491-
// 0, getting to here necessarily means the `RawVec` is overfull.
492-
return Err(CapacityOverflow);
493-
}
494494
// Since we guarantee that we never allocate more than `isize::MAX` bytes,
495495
// `elem_size * self.cap <= isize::MAX` as a precondition, so this can't overflow.
496496
// Additionally the alignment will never be too large as to "not be satisfiable",

0 commit comments

Comments
 (0)