@@ -440,6 +440,7 @@ impl<T: Ord> BinaryHeap<T> {
440
440
/// assert_eq!(heap.pop(), Some(5));
441
441
/// ```
442
442
// #[stable(feature = "rust1", since = "1.0.0")]
443
+ #[ must_use]
443
444
pub fn new ( ) -> Self {
444
445
BinaryHeap :: from_vec ( vec ! [ ] )
445
446
}
@@ -465,6 +466,7 @@ impl<T: Ord> BinaryHeap<T> {
465
466
/// assert_eq!(heap.pop(), Some(5));
466
467
/// ```
467
468
// #[stable(feature = "rust1", since = "1.0.0")]
469
+ #[ must_use]
468
470
pub fn with_capacity ( capacity : usize ) -> Self {
469
471
BinaryHeap :: from_vec ( Vec :: with_capacity ( capacity) )
470
472
}
@@ -487,6 +489,7 @@ impl<T: Ord> BinaryHeap<T, MinComparator> {
487
489
/// heap.push(5);
488
490
/// assert_eq!(heap.pop(), Some(1));
489
491
/// ```
492
+ #[ must_use]
490
493
pub fn new_min ( ) -> Self {
491
494
BinaryHeap :: from_vec ( vec ! [ ] )
492
495
}
@@ -511,6 +514,7 @@ impl<T: Ord> BinaryHeap<T, MinComparator> {
511
514
/// heap.push(5);
512
515
/// assert_eq!(heap.pop(), Some(1));
513
516
/// ```
517
+ #[ must_use]
514
518
pub fn with_capacity_min ( capacity : usize ) -> Self {
515
519
BinaryHeap :: from_vec ( Vec :: with_capacity ( capacity) )
516
520
}
@@ -536,6 +540,7 @@ where
536
540
/// heap.push(5);
537
541
/// assert_eq!(heap.pop(), Some(1));
538
542
/// ```
543
+ #[ must_use]
539
544
pub fn new_by ( f : F ) -> Self {
540
545
BinaryHeap :: from_vec_cmp ( vec ! [ ] , FnComparator ( f) )
541
546
}
@@ -560,6 +565,7 @@ where
560
565
/// heap.push(5);
561
566
/// assert_eq!(heap.pop(), Some(1));
562
567
/// ```
568
+ #[ must_use]
563
569
pub fn with_capacity_by ( capacity : usize , f : F ) -> Self {
564
570
BinaryHeap :: from_vec_cmp ( Vec :: with_capacity ( capacity) , FnComparator ( f) )
565
571
}
@@ -585,6 +591,7 @@ where
585
591
/// heap.push(5);
586
592
/// assert_eq!(heap.pop(), Some(3));
587
593
/// ```
594
+ #[ must_use]
588
595
pub fn new_by_key ( f : F ) -> Self {
589
596
BinaryHeap :: from_vec_cmp ( vec ! [ ] , KeyComparator ( f) )
590
597
}
@@ -609,6 +616,7 @@ where
609
616
/// heap.push(5);
610
617
/// assert_eq!(heap.pop(), Some(3));
611
618
/// ```
619
+ #[ must_use]
612
620
pub fn with_capacity_by_key ( capacity : usize , f : F ) -> Self {
613
621
BinaryHeap :: from_vec_cmp ( Vec :: with_capacity ( capacity) , KeyComparator ( f) )
614
622
}
@@ -723,6 +731,7 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
723
731
/// assert_eq!(heap.peek(), Some(&5));
724
732
///
725
733
/// ```
734
+ #[ must_use]
726
735
// #[stable(feature = "rust1", since = "1.0.0")]
727
736
pub fn peek ( & self ) -> Option < & T > {
728
737
self . data . get ( 0 )
@@ -776,6 +785,7 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
776
785
/// assert!(heap.capacity() >= 100);
777
786
/// heap.push(4);
778
787
/// ```
788
+ #[ must_use]
779
789
// #[stable(feature = "rust1", since = "1.0.0")]
780
790
pub fn capacity ( & self ) -> usize {
781
791
self . data . capacity ( )
@@ -921,6 +931,7 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
921
931
/// println!("{}", x);
922
932
/// }
923
933
/// ```
934
+ #[ must_use = "`self` will be dropped if the result is not used" ]
924
935
// #[stable(feature = "binary_heap_extras_15", since = "1.5.0")]
925
936
pub fn into_vec ( self ) -> Vec < T > {
926
937
self . into ( )
@@ -943,6 +954,7 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
943
954
/// let vec = heap.into_sorted_vec();
944
955
/// assert_eq!(vec, [1, 2, 3, 4, 5, 6, 7]);
945
956
/// ```
957
+ #[ must_use = "`self` will be dropped if the result is not used" ]
946
958
// #[stable(feature = "binary_heap_extras_15", since = "1.5.0")]
947
959
pub fn into_sorted_vec ( mut self ) -> Vec < T > {
948
960
let mut end = self . len ( ) ;
@@ -1119,6 +1131,7 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
1119
1131
///
1120
1132
/// assert_eq!(heap.len(), 2);
1121
1133
/// ```
1134
+ #[ must_use]
1122
1135
// #[stable(feature = "rust1", since = "1.0.0")]
1123
1136
pub fn len ( & self ) -> usize {
1124
1137
self . data . len ( )
@@ -1142,6 +1155,7 @@ impl<T, C: Compare<T>> BinaryHeap<T, C> {
1142
1155
///
1143
1156
/// assert!(!heap.is_empty());
1144
1157
/// ```
1158
+ #[ must_use]
1145
1159
// #[stable(feature = "rust1", since = "1.0.0")]
1146
1160
pub fn is_empty ( & self ) -> bool {
1147
1161
self . len ( ) == 0
@@ -1362,6 +1376,7 @@ impl<T> Drop for Hole<'_, T> {
1362
1376
///
1363
1377
/// [`iter`]: struct.BinaryHeap.html#method.iter
1364
1378
/// [`BinaryHeap`]: struct.BinaryHeap.html
1379
+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
1365
1380
// #[stable(feature = "rust1", since = "1.0.0")]
1366
1381
pub struct Iter < ' a , T : ' a > {
1367
1382
iter : slice:: Iter < ' a , T > ,
@@ -1472,6 +1487,7 @@ impl<T> DoubleEndedIterator for IntoIter<T> {
1472
1487
// #[stable(feature = "fused", since = "1.26.0")]
1473
1488
// impl<T> FusedIterator for IntoIter<T> {}
1474
1489
1490
+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
1475
1491
// #[unstable(feature = "binary_heap_into_iter_sorted", issue = "59278")]
1476
1492
#[ derive( Clone , Debug ) ]
1477
1493
pub struct IntoIterSorted < T , C : Compare < T > > {
0 commit comments