about summary refs log tree commit diff
path: root/library/alloc/src/collections
diff options
context:
space:
mode:
authorEFanZh <efanzh@gmail.com>2024-10-03 22:15:52 +0800
committerEFanZh <efanzh@gmail.com>2024-10-03 22:15:52 +0800
commitd47e388843f682f57262f020edd9909c850a0c49 (patch)
tree9e026e331e81a76b6586d63eb064ab9ddcd43d5b /library/alloc/src/collections
parent9c7013c15c189a6978ac8b9dac638581495527de (diff)
downloadrust-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.rs5
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() }
     }
 }