@@ -440,6 +440,7 @@ impl<T: Ord> BinaryHeap<T> {
440440 /// assert_eq!(heap.pop(), Some(5));
441441 /// ```
442442 // #[stable(feature = "rust1", since = "1.0.0")]
443+ #[ must_use]
443444 pub fn new ( ) -> Self {
444445 BinaryHeap :: from_vec ( vec ! [ ] )
445446 }
@@ -465,6 +466,7 @@ impl<T: Ord> BinaryHeap<T> {
465466 /// assert_eq!(heap.pop(), Some(5));
466467 /// ```
467468 // #[stable(feature = "rust1", since = "1.0.0")]
469+ #[ must_use]
468470 pub fn with_capacity ( capacity : usize ) -> Self {
469471 BinaryHeap :: from_vec ( Vec :: with_capacity ( capacity) )
470472 }
@@ -487,6 +489,7 @@ impl<T: Ord> BinaryHeap<T, MinComparator> {
487489 /// heap.push(5);
488490 /// assert_eq!(heap.pop(), Some(1));
489491 /// ```
492+ #[ must_use]
490493 pub fn new_min ( ) -> Self {
491494 BinaryHeap :: from_vec ( vec ! [ ] )
492495 }
@@ -511,6 +514,7 @@ impl<T: Ord> BinaryHeap<T, MinComparator> {
511514 /// heap.push(5);
512515 /// assert_eq!(heap.pop(), Some(1));
513516 /// ```
517+ #[ must_use]
514518 pub fn with_capacity_min ( capacity : usize ) -> Self {
515519 BinaryHeap :: from_vec ( Vec :: with_capacity ( capacity) )
516520 }
@@ -536,6 +540,7 @@ where
536540 /// heap.push(5);
537541 /// assert_eq!(heap.pop(), Some(1));
538542 /// ```
543+ #[ must_use]
539544 pub fn new_by ( f : F ) -> Self {
540545 BinaryHeap :: from_vec_cmp ( vec ! [ ] , FnComparator ( f) )
541546 }
@@ -560,6 +565,7 @@ where
560565 /// heap.push(5);
561566 /// assert_eq!(heap.pop(), Some(1));
562567 /// ```
568+ #[ must_use]
563569 pub fn with_capacity_by ( capacity : usize , f : F ) -> Self {
564570 BinaryHeap :: from_vec_cmp ( Vec :: with_capacity ( capacity) , FnComparator ( f) )
565571 }
@@ -585,6 +591,7 @@ where
585591 /// heap.push(5);
586592 /// assert_eq!(heap.pop(), Some(3));
587593 /// ```
594+ #[ must_use]
588595 pub fn new_by_key ( f : F ) -> Self {
589596 BinaryHeap :: from_vec_cmp ( vec ! [ ] , KeyComparator ( f) )
590597 }
@@ -609,6 +616,7 @@ where
609616 /// heap.push(5);
610617 /// assert_eq!(heap.pop(), Some(3));
611618 /// ```
619+ #[ must_use]
612620 pub fn with_capacity_by_key ( capacity : usize , f : F ) -> Self {
613621 BinaryHeap :: from_vec_cmp ( Vec :: with_capacity ( capacity) , KeyComparator ( f) )
614622 }
@@ -723,6 +731,7 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
723731 /// assert_eq!(heap.peek(), Some(&5));
724732 ///
725733 /// ```
734+ #[ must_use]
726735 // #[stable(feature = "rust1", since = "1.0.0")]
727736 pub fn peek ( & self ) -> Option < & T > {
728737 self . data . get ( 0 )
@@ -776,6 +785,7 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
776785 /// assert!(heap.capacity() >= 100);
777786 /// heap.push(4);
778787 /// ```
788+ #[ must_use]
779789 // #[stable(feature = "rust1", since = "1.0.0")]
780790 pub fn capacity ( & self ) -> usize {
781791 self . data . capacity ( )
@@ -921,6 +931,7 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
921931 /// println!("{}", x);
922932 /// }
923933 /// ```
934+ #[ must_use = "`self` will be dropped if the result is not used" ]
924935 // #[stable(feature = "binary_heap_extras_15", since = "1.5.0")]
925936 pub fn into_vec ( self ) -> Vec < T > {
926937 self . into ( )
@@ -943,6 +954,7 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
943954 /// let vec = heap.into_sorted_vec();
944955 /// assert_eq!(vec, [1, 2, 3, 4, 5, 6, 7]);
945956 /// ```
957+ #[ must_use = "`self` will be dropped if the result is not used" ]
946958 // #[stable(feature = "binary_heap_extras_15", since = "1.5.0")]
947959 pub fn into_sorted_vec ( mut self ) -> Vec < T > {
948960 let mut end = self . len ( ) ;
@@ -1119,6 +1131,7 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
11191131 ///
11201132 /// assert_eq!(heap.len(), 2);
11211133 /// ```
1134+ #[ must_use]
11221135 // #[stable(feature = "rust1", since = "1.0.0")]
11231136 pub fn len ( & self ) -> usize {
11241137 self . data . len ( )
@@ -1142,6 +1155,7 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
11421155 ///
11431156 /// assert!(!heap.is_empty());
11441157 /// ```
1158+ #[ must_use]
11451159 // #[stable(feature = "rust1", since = "1.0.0")]
11461160 pub fn is_empty ( & self ) -> bool {
11471161 self . len ( ) == 0
@@ -1362,6 +1376,7 @@ impl<T> Drop for Hole<'_, T> {
13621376///
13631377/// [`iter`]: struct.BinaryHeap.html#method.iter
13641378/// [`BinaryHeap`]: struct.BinaryHeap.html
1379+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
13651380// #[stable(feature = "rust1", since = "1.0.0")]
13661381pub struct Iter < ' a , T : ' a > {
13671382 iter : slice:: Iter < ' a , T > ,
@@ -1472,6 +1487,7 @@ impl<T> DoubleEndedIterator for IntoIter<T> {
14721487// #[stable(feature = "fused", since = "1.26.0")]
14731488// impl<T> FusedIterator for IntoIter<T> {}
14741489
1490+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
14751491// #[unstable(feature = "binary_heap_into_iter_sorted", issue = "59278")]
14761492#[ derive( Clone , Debug ) ]
14771493pub struct IntoIterSorted < T , C : Compare < T > > {
0 commit comments