Skip to content

Commit

Permalink
Clarify safety comment
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Dec 31, 2021
1 parent 4f80816 commit 777c853
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 777c853

Please sign in to comment.