Skip to content

Commit

Permalink
Add FIXME for safety comments that are invalid when T is a ZST
Browse files Browse the repository at this point in the history
  • Loading branch information
SkiFire13 authored and Mark-Simulacrum committed Feb 20, 2021
1 parent 9b4e612 commit 3ec1a28
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions library/alloc/src/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ impl<T: Ord> BinaryHeap<T> {
// child + 1 < end <= self.len(), so they're valid indexes.
// child == 2 * hole.pos() + 1 != hole.pos() and
// child + 1 == 2 * hole.pos() + 2 != hole.pos().
// FIXME: 2 * hole.pos() + 1 or 2 * hole.pos() + 2 could overflow
// if T is a ZST
child += unsafe { hole.get(child) <= hole.get(child + 1) } as usize;

// if we are already in order, stop.
Expand Down Expand Up @@ -627,6 +629,8 @@ impl<T: Ord> BinaryHeap<T> {
// child + 1 < end <= self.len(), so they're valid indexes.
// child == 2 * hole.pos() + 1 != hole.pos() and
// child + 1 == 2 * hole.pos() + 2 != hole.pos().
// FIXME: 2 * hole.pos() + 1 or 2 * hole.pos() + 2 could overflow
// if T is a ZST
child += unsafe { hole.get(child) <= hole.get(child + 1) } as usize;

// SAFETY: Same as above
Expand Down

0 comments on commit 3ec1a28

Please sign in to comment.