Skip to content

Commit 0191b93

Browse files
kornelskiscottmcm
andauthored
Update library/alloc/src/raw_vec.rs
Co-authored-by: scottmcm <[email protected]>
1 parent 9a55d7a commit 0191b93

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

library/alloc/src/raw_vec.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,14 @@ impl<T, A: Allocator> RawVec<T, A> {
291291

292292
if self.needs_to_grow(len, additional) {
293293
do_reserve_and_handle(self, len, additional);
294-
unsafe {
295-
// Inform the optimizer that the reservation has succeeded
296-
core::intrinsics::assume(!self.needs_to_grow(len, additional));
297-
}
294+
}
295+
296+
// SAFETY: The call to `do_reserve_and_handle` ensured this
297+
// (or it panicked) and thus the addition cannot overflow.
298+
unsafe {
299+
// Inform the optimizer that the reservation has succeeded
300+
let min_cap = len.unchecked_add(additional);
301+
core::intrinsics::assume(self.cap >= min_cap);
298302
}
299303
}
300304

0 commit comments

Comments
 (0)