Clarify safety comment

This commit is contained in:
Ben Kimock 2021-12-31 18:03:07 -05:00
parent 4f808161bc
commit 777c853b4a

View File

@ -2144,6 +2144,8 @@ impl<T, A: Allocator> Vec<T, A> {
let ptr = self.as_mut_ptr();
// SAFETY:
// - `ptr` is guaranteed to be valid for `self.len` elements
// - but the allocation extends out to `self.buf.capacity()` elements, possibly
// uninitialized
let spare_ptr = unsafe { ptr.add(self.len) };
let spare_ptr = spare_ptr.cast::<MaybeUninit<T>>();
let spare_len = self.buf.capacity() - self.len;