diff options
| author | The8472 <git@infinite-source.de> | 2021-06-21 21:29:43 +0200 |
|---|---|---|
| committer | The8472 <git@infinite-source.de> | 2021-06-22 19:06:55 +0200 |
| commit | e0d70153cdee47421b0ec9220dc8fea65f243cfe (patch) | |
| tree | 6a5310f4f3ea2d90c40a5b1366fbc4ab67ad8abe /library/alloc/src/vec/mod.rs | |
| parent | 6a5b97adb4da4b0f913d19765e91d4322ef6542e (diff) | |
| download | rust-e0d70153cdee47421b0ec9220dc8fea65f243cfe.tar.gz rust-e0d70153cdee47421b0ec9220dc8fea65f243cfe.zip | |
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.
Diffstat (limited to 'library/alloc/src/vec/mod.rs')
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index b59d2977add..f3a47cba759 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -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); } |
