@@ -386,7 +386,24 @@ where
386386
387387 /// Removes the *top* (greatest if max-heap, smallest if min-heap) item from the binary heap and
388388 /// returns it, without checking if the binary heap is empty.
389- #[ allow( clippy:: missing_safety_doc) ] // TODO
389+ ///
390+ /// # Safety
391+ ///
392+ /// The binary heap must not be empty.
393+ ///
394+ /// # Example
395+ ///
396+ /// ```
397+ /// use heapless::binary_heap::{BinaryHeap, Max};
398+ ///
399+ /// let mut heap: BinaryHeap<_, Max, 8> = BinaryHeap::new();
400+ /// heap.push(42)?;
401+ ///
402+ /// // SAFETY: We just pushed a number onto the heap, so it cannot be empty.
403+ /// let val = unsafe { heap.pop_unchecked() };
404+ /// assert_eq!(val, 42);
405+ /// # Ok::<(), u8>(())
406+ /// ```
390407 pub unsafe fn pop_unchecked ( & mut self ) -> T {
391408 let mut item = self . data . pop_unchecked ( ) ;
392409
@@ -420,7 +437,25 @@ where
420437 }
421438
422439 /// Pushes an item onto the binary heap without first checking if it's full.
423- #[ allow( clippy:: missing_safety_doc) ] // TODO
440+ ///
441+ /// # Safety
442+ ///
443+ /// The binary heap must not be full.
444+ ///
445+ /// # Example
446+ ///
447+ /// ```
448+ /// use heapless::binary_heap::{BinaryHeap, Max};
449+ ///
450+ /// let mut heap: BinaryHeap<_, Max, 8> = BinaryHeap::new();
451+ ///
452+ /// if !heap.is_full() {
453+ /// // SAFETY: the heap is not full
454+ /// unsafe { heap.push_unchecked(42) };
455+ /// }
456+ /// assert_eq!(heap.len(), 1);
457+ /// assert_eq!(heap.peek(), Some(&42));
458+ /// ```
424459 pub unsafe fn push_unchecked ( & mut self , item : T ) {
425460 let old_len = self . len ( ) ;
426461 self . data . push_unchecked ( item) ;
0 commit comments