diff --git a/library/alloc/src/collections/binary_heap/mod.rs b/library/alloc/src/collections/binary_heap/mod.rs index 65c8d5213f16..97aafbc7b699 100644 --- a/library/alloc/src/collections/binary_heap/mod.rs +++ b/library/alloc/src/collections/binary_heap/mod.rs @@ -656,14 +656,15 @@ impl BinaryHeap { /// # Examples /// /// ``` + /// #![feature(binary_heap_pop_if)] /// use std::collections::BinaryHeap; /// let mut heap = BinaryHeap::from([1, 2]); /// let pred = |x: &i32| *x % 2 == 0; /// /// assert_eq!(heap.pop_if(pred), Some(2)); - /// assert_eq!(heap, BinaryHeap::from([1])); + /// assert_eq!(heap.as_slice(), [1]); /// assert_eq!(heap.pop_if(pred), None); - /// assert_eq!(heap, BinaryHeap::from([1])); + /// assert_eq!(heap.as_slice(), [1]); /// ``` /// /// # Time complexity @@ -671,7 +672,7 @@ impl BinaryHeap { /// The worst case cost of `pop_if` on a heap containing *n* elements is *O*(log(*n*)). #[unstable(feature = "binary_heap_pop_if", issue = "151828")] pub fn pop_if(&mut self, predicate: impl FnOnce(&T) -> bool) -> Option { - let first = self.data.first()?; + let first = self.peek()?; if predicate(first) { self.pop() } else { None } } diff --git a/library/alloctests/lib.rs b/library/alloctests/lib.rs index 9806c59ce0e1..fe14480102e3 100644 --- a/library/alloctests/lib.rs +++ b/library/alloctests/lib.rs @@ -17,7 +17,6 @@ #![feature(allocator_api)] #![feature(array_into_iter_constructors)] #![feature(assert_matches)] -#![feature(binary_heap_pop_if)] #![feature(box_vec_non_null)] #![feature(char_internals)] #![feature(const_alloc_error)] diff --git a/library/alloctests/tests/collections/binary_heap.rs b/library/alloctests/tests/collections/binary_heap.rs index 1b6afec7f355..e1484c32a4f8 100644 --- a/library/alloctests/tests/collections/binary_heap.rs +++ b/library/alloctests/tests/collections/binary_heap.rs @@ -145,7 +145,7 @@ fn test_pop_if() { while let Some(popped) = heap.pop_if(|x| *x > 2) { assert_eq!(popped, sorted.pop().unwrap()); } - assert_eq!(heap.into_sorted_vec(), vec![1, 2]); + assert_eq!(heap.into_sorted_vec(), vec![0, 1, 2]); } #[test] diff --git a/library/alloctests/tests/lib.rs b/library/alloctests/tests/lib.rs index 2926248edbf5..e15c86496cf1 100644 --- a/library/alloctests/tests/lib.rs +++ b/library/alloctests/tests/lib.rs @@ -1,4 +1,5 @@ #![feature(allocator_api)] +#![feature(binary_heap_pop_if)] #![feature(const_heap)] #![feature(deque_extend_front)] #![feature(iter_array_chunks)]