We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8d15753 commit 387568cCopy full SHA for 387568c
library/alloc/src/collections/binary_heap.rs
@@ -495,6 +495,10 @@ impl<T: Ord> BinaryHeap<T> {
495
let mut end = self.len();
496
while end > 1 {
497
end -= 1;
498
+ // SAFETY: `end` goes from `self.len() - 1` to 1 (both included),
499
+ // so it's always a valid index to access.
500
+ // It is safe to access index 0 (i.e. `ptr`), because
501
+ // 1 <= end < self.len(), which means self.len() >= 2.
502
unsafe {
503
let ptr = self.data.as_mut_ptr();
504
ptr::swap(ptr, ptr.add(end));
0 commit comments