diff options
| author | Philippe-Cholet <44676486+Philippe-Cholet@users.noreply.github.com> | 2024-04-08 12:12:13 +0200 |
|---|---|---|
| committer | Philippe-Cholet <44676486+Philippe-Cholet@users.noreply.github.com> | 2024-04-08 12:12:13 +0200 |
| commit | 7a2678de7d3c0caa169542bd56a4fbf41b73a5b5 (patch) | |
| tree | 98c255136dbf53582cb78d71f15a621981460a65 /library/alloc/src | |
| parent | 7a495cc13d4361067d471faa3267dcdbacb3206c (diff) | |
| download | rust-7a2678de7d3c0caa169542bd56a4fbf41b73a5b5.tar.gz rust-7a2678de7d3c0caa169542bd56a4fbf41b73a5b5.zip | |
Add invariant to VecDeque::pop_* that len < cap if pop successful
Similar to #114370 for VecDeque instead of Vec. It now uses `core::hint::assert_unchecked`.
Diffstat (limited to 'library/alloc/src')
| -rw-r--r-- | library/alloc/src/collections/vec_deque/mod.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index e2fc320f280..693ecb0b6b4 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -1614,7 +1614,10 @@ impl<T, A: Allocator> VecDeque<T, A> { let old_head = self.head; self.head = self.to_physical_idx(1); self.len -= 1; - Some(unsafe { self.buffer_read(old_head) }) + unsafe { + core::hint::assert_unchecked(self.len < self.capacity()); + Some(self.buffer_read(old_head)) + } } } @@ -1638,7 +1641,10 @@ impl<T, A: Allocator> VecDeque<T, A> { None } else { self.len -= 1; - Some(unsafe { self.buffer_read(self.to_physical_idx(self.len)) }) + unsafe { + core::hint::assert_unchecked(self.len < self.capacity()); + Some(self.buffer_read(self.to_physical_idx(self.len))) + } } } |
