Skip to content

Commit

Permalink
Rollup merge of #72366 - nnethercote:tiny-vecs-are-dumb-followup, r=A…
Browse files Browse the repository at this point in the history
…manieu

Adjust the zero check in `RawVec::grow`.

This was supposed to land as part of #72227. (I wish `git push` would
abort when you have uncommited changes.)

r? @Amanieu
  • Loading branch information
Dylan-DPC committed May 20, 2020
2 parents 04d5d15 + 9eb0399 commit 1841240
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/liballoc/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,16 +401,15 @@ impl<T, A: AllocRef> RawVec<T, A> {
needed_extra_capacity: usize,
placement: ReallocPlacement,
) -> Result<(), TryReserveError> {
// This is ensured by the calling contexts.
debug_assert!(needed_extra_capacity > 0);

if mem::size_of::<T>() == 0 {
// Since we return a capacity of `usize::MAX` when `elem_size` is
// 0, getting to here necessarily means the `RawVec` is overfull.
return Err(CapacityOverflow);
}

if needed_extra_capacity == 0 {
return Ok(());
}

// Nothing we can really do about these checks, sadly.
let required_cap =
used_capacity.checked_add(needed_extra_capacity).ok_or(CapacityOverflow)?;
Expand Down

0 comments on commit 1841240

Please sign in to comment.