diff options
| author | EFanZh <efanzh@gmail.com> | 2024-10-03 22:15:52 +0800 |
|---|---|---|
| committer | EFanZh <efanzh@gmail.com> | 2024-10-03 22:15:52 +0800 |
| commit | d47e388843f682f57262f020edd9909c850a0c49 (patch) | |
| tree | 9e026e331e81a76b6586d63eb064ab9ddcd43d5b /library/alloc/src/collections | |
| parent | 9c7013c15c189a6978ac8b9dac638581495527de (diff) | |
| download | rust-d47e388843f682f57262f020edd9909c850a0c49.tar.gz rust-d47e388843f682f57262f020edd9909c850a0c49.zip | |
Avoid emptiness check in `PeekMut::pop`
Diffstat (limited to 'library/alloc/src/collections')
| -rw-r--r-- | library/alloc/src/collections/binary_heap/mod.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 5e59abf54ee..59f10b09c73 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -374,7 +374,10 @@ impl<'a, T: Ord, A: Allocator> PeekMut<'a, T, A> { // the caller could've mutated the element. It is removed from the // heap on the next line and pop() is not sensitive to its value. } - this.heap.pop().unwrap() + + // SAFETY: Have a `PeekMut` element proves that the associated binary heap being non-empty, + // so the `pop` operation will not fail. + unsafe { this.heap.pop().unwrap_unchecked() } } } |
