diff options
| author | 2022-05-09 15:07:03 +0200 | |
|---|---|---|
| committer | 2022-05-09 15:07:03 +0200 | |
| commit | 5c39f5c7ee2e87a2a431e3c8390d71ecabaf6d65 (patch) | |
| tree | 08178532d16d7e54537eaa8fd4aebb7270418a84 /src/binary_heap.rs | |
| parent | 6877eedfd4ff0c19f66b504cfe523e8d3f097884 (diff) | |
| download | heapless-5c39f5c7ee2e87a2a431e3c8390d71ecabaf6d65.tar.gz heapless-5c39f5c7ee2e87a2a431e3c8390d71ecabaf6d65.tar.zst heapless-5c39f5c7ee2e87a2a431e3c8390d71ecabaf6d65.zip | |
fix: BinaryHeap elements are dropped twice
Diffstat (limited to '')
| -rw-r--r-- | src/binary_heap.rs | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/src/binary_heap.rs b/src/binary_heap.rs index dc9ea590..5bf01827 100644 --- a/src/binary_heap.rs +++ b/src/binary_heap.rs @@ -537,12 +537,6 @@ where } } -impl<T, K, const N: usize> Drop for BinaryHeap<T, K, N> { - fn drop(&mut self) { - unsafe { ptr::drop_in_place(self.data.as_mut_slice()) } - } -} - impl<T, K, const N: usize> fmt::Debug for BinaryHeap<T, K, N> where K: Kind, @@ -578,6 +572,45 @@ mod tests { } #[test] + fn drop() { + droppable!(); + + { + let mut v: BinaryHeap<Droppable, Max, 2> = BinaryHeap::new(); + v.push(Droppable::new()).ok().unwrap(); + v.push(Droppable::new()).ok().unwrap(); + v.pop().unwrap(); + } + + assert_eq!(unsafe { COUNT }, 0); + + { + let mut v: BinaryHeap<Droppable, Max, 2> = BinaryHeap::new(); + v.push(Droppable::new()).ok().unwrap(); + v.push(Droppable::new()).ok().unwrap(); + } + + assert_eq!(unsafe { COUNT }, 0); + + { + let mut v: BinaryHeap<Droppable, Min, 2> = BinaryHeap::new(); + v.push(Droppable::new()).ok().unwrap(); + v.push(Droppable::new()).ok().unwrap(); + v.pop().unwrap(); + } + + assert_eq!(unsafe { COUNT }, 0); + + { + let mut v: BinaryHeap<Droppable, Min, 2> = BinaryHeap::new(); + v.push(Droppable::new()).ok().unwrap(); + v.push(Droppable::new()).ok().unwrap(); + } + + assert_eq!(unsafe { COUNT }, 0); + } + + #[test] fn min() { let mut heap = BinaryHeap::<_, Min, 16>::new(); heap.push(1).unwrap(); |
