The Onomicon has the following:
We would rather have the following:
bubble_up(heap, index): let elem = heap[index] while index != 0 && elem < heap[parent(index)]: heap[index] = heap[parent(index)] index = parent(index) heap[index] = elem
This code ensures that each element is copied as little as possible (it is in fact necessary that elem be copied twice in general). However it now exposes some exception safety trouble! At all times, there exists two copies of one value. If we panic in this function something will be double-dropped. Unfortunately, we also don't have full control of the code: that comparison is user-defined!
I can't undetstand the mentioned double-drop.
heap[index] = heap[parent(index)] is a movement, then heap[parent(index)] is uninitiated, so only one drop. If it is a Copy, then T: !Drop, no dropping at all.