Add comments around code where ordering is important due for panic-safety
Iterators contain arbitrary code which may panic. Unsafe code has to be careful to do its state updates at the right point between calls that may panic.
This commit is contained in:
parent
6a5b97adb4
commit
e0d70153cd
4 changed files with 17 additions and 0 deletions
|
@ -2568,6 +2568,8 @@ impl<T, A: Allocator> Vec<T, A> {
|
|||
}
|
||||
unsafe {
|
||||
ptr::write(self.as_mut_ptr().add(len), element);
|
||||
// Since next() executes user code which can panic we have to bump the length
|
||||
// after each step.
|
||||
// NB can't overflow since we would have had to alloc the address space
|
||||
self.set_len(len + 1);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue