diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index 41adc2e79dc..742daea873e 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -2086,10 +2086,9 @@ impl VecDeque { // Extend or possibly remove this assertion when valid use-cases for growing the // buffer without it being full emerge debug_assert!(self.is_full()); - let old_cap = self.capacity(); - self.buf.reserve_for_push(old_cap); + self.buf.reserve_for_push(); unsafe { - self.handle_capacity_increase(old_cap); + self.handle_capacity_increase(self.capacity()); } debug_assert!(!self.is_full()); } diff --git a/library/alloc/src/raw_vec.rs b/library/alloc/src/raw_vec.rs index 175e23b543c..45258cc86ff 100644 --- a/library/alloc/src/raw_vec.rs +++ b/library/alloc/src/raw_vec.rs @@ -349,8 +349,8 @@ impl RawVec { /// oft-instantiated `Vec::push()`, which does its own capacity check. #[cfg(not(no_global_oom_handling))] #[inline(never)] - pub fn reserve_for_push(&mut self, len: usize) { - if let Err(err) = self.grow_amortized(len, 1) { + pub fn reserve_for_push(&mut self) { + if let Err(err) = self.grow_amortized(self.cap.0, 1) { handle_error(err); } } diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 8ca8046dac5..5f4c45d578d 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1547,7 +1547,7 @@ impl Vec { // space for the new element if len == self.buf.capacity() { - self.reserve(1); + self.buf.reserve_for_push(); } unsafe { @@ -1967,7 +1967,7 @@ impl Vec { // This will panic or abort if we would allocate > isize::MAX bytes // or if the length increment would overflow for zero-sized types. if self.len == self.buf.capacity() { - self.buf.reserve_for_push(self.len); + self.buf.reserve_for_push(); } unsafe { let end = self.as_mut_ptr().add(self.len);