about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGiacomo Stevanato <giaco.stevanato@gmail.com>2020-08-26 23:52:20 +0200
committerGiacomo Stevanato <giaco.stevanato@gmail.com>2020-09-20 01:12:02 +0200
commitaf1e3633f734930a50000cc424fbcdc6629885c3 (patch)
tree51c4d7066cf74cb026273cdc8b19c3fda4797950
parent924cd135b6ab0fe48dae26d9ae30eaadebcd066d (diff)
downloadrust-af1e3633f734930a50000cc424fbcdc6629885c3.tar.gz
rust-af1e3633f734930a50000cc424fbcdc6629885c3.zip
Set sift=true only when PeekMut yields a mutable reference
-rw-r--r--library/alloc/src/collections/binary_heap.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/library/alloc/src/collections/binary_heap.rs b/library/alloc/src/collections/binary_heap.rs
index 477a598ff5b..e3b738a70c8 100644
--- a/library/alloc/src/collections/binary_heap.rs
+++ b/library/alloc/src/collections/binary_heap.rs
@@ -293,6 +293,7 @@ impl<T: Ord> Deref for PeekMut<'_, T> {
 impl<T: Ord> DerefMut for PeekMut<'_, T> {
     fn deref_mut(&mut self) -> &mut T {
         debug_assert!(!self.heap.is_empty());
+        self.sift = true;
         // SAFE: PeekMut is only instantiated for non-empty heaps
         unsafe { self.heap.data.get_unchecked_mut(0) }
     }
@@ -401,7 +402,7 @@ impl<T: Ord> BinaryHeap<T> {
     /// Cost is *O*(1) in the worst case.
     #[stable(feature = "binary_heap_peek_mut", since = "1.12.0")]
     pub fn peek_mut(&mut self) -> Option<PeekMut<'_, T>> {
-        if self.is_empty() { None } else { Some(PeekMut { heap: self, sift: true }) }
+        if self.is_empty() { None } else { Some(PeekMut { heap: self, sift: false }) }
     }
 
     /// Removes the greatest item from the binary heap and returns it, or `None` if it