add #[must_use] to functions of slice and its iterators. · rust-lang/rust@dcdde01 (original) (raw)
`@@ -62,6 +62,7 @@ fn size_from_ptr(_: *const T) -> usize {
`
62
62
`` /// [iter
]: slice::iter
``
63
63
`/// [slices]: slice
`
64
64
`#[stable(feature = "rust1", since = "1.0.0")]
`
``
65
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
65
66
`pub struct Iter<'a, T: 'a> {
`
66
67
`ptr: NonNull,
`
67
68
`end: *const T, // If T is a ZST, this is actually ptr+len. This encoding is picked so that
`
`@@ -182,6 +183,7 @@ impl AsRef<[T]> for Iter<'_, T> {
`
182
183
`` /// [iter_mut
]: slice::iter_mut
``
183
184
`/// [slices]: slice
`
184
185
`#[stable(feature = "rust1", since = "1.0.0")]
`
``
186
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
185
187
`pub struct IterMut<'a, T: 'a> {
`
186
188
`ptr: NonNull,
`
187
189
`end: *mut T, // If T is a ZST, this is actually ptr+len. This encoding is picked so that
`
`@@ -339,6 +341,7 @@ pub(super) trait SplitIter: DoubleEndedIterator {
`
339
341
`` /// [split
]: slice::split
``
340
342
`/// [slices]: slice
`
341
343
`#[stable(feature = "rust1", since = "1.0.0")]
`
``
344
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
342
345
`pub struct Split<'a, T: 'a, P>
`
343
346
`where
`
344
347
`P: FnMut(&T) -> bool,
`
`@@ -469,6 +472,7 @@ impl<T, P> FusedIterator for Split<'_, T, P> where P: FnMut(&T) -> bool {}
`
469
472
`` /// [split_inclusive
]: slice::split_inclusive
``
470
473
`/// [slices]: slice
`
471
474
`#[stable(feature = "split_inclusive", since = "1.51.0")]
`
``
475
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
472
476
`pub struct SplitInclusive<'a, T: 'a, P>
`
473
477
`where
`
474
478
`P: FnMut(&T) -> bool,
`
`@@ -589,6 +593,7 @@ impl<T, P> FusedIterator for SplitInclusive<'_, T, P> where P: FnMut(&T) -> bool
`
589
593
`` /// [split_mut
]: slice::split_mut
``
590
594
`/// [slices]: slice
`
591
595
`#[stable(feature = "rust1", since = "1.0.0")]
`
``
596
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
592
597
`pub struct SplitMut<'a, T: 'a, P>
`
593
598
`where
`
594
599
`P: FnMut(&T) -> bool,
`
`@@ -718,6 +723,7 @@ impl<T, P> FusedIterator for SplitMut<'_, T, P> where P: FnMut(&T) -> bool {}
`
718
723
`` /// [split_inclusive_mut
]: slice::split_inclusive_mut
``
719
724
`/// [slices]: slice
`
720
725
`#[stable(feature = "split_inclusive", since = "1.51.0")]
`
``
726
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
721
727
`pub struct SplitInclusiveMut<'a, T: 'a, P>
`
722
728
`where
`
723
729
`P: FnMut(&T) -> bool,
`
`@@ -841,6 +847,7 @@ impl<T, P> FusedIterator for SplitInclusiveMut<'_, T, P> where P: FnMut(&T) -> b
`
841
847
`` /// [rsplit
]: slice::rsplit
``
842
848
`/// [slices]: slice
`
843
849
`#[stable(feature = "slice_rsplit", since = "1.27.0")]
`
``
850
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
844
851
`pub struct RSplit<'a, T: 'a, P>
`
845
852
`where
`
846
853
`P: FnMut(&T) -> bool,
`
`@@ -937,6 +944,7 @@ impl<T, P> FusedIterator for RSplit<'_, T, P> where P: FnMut(&T) -> bool {}
`
937
944
`` /// [rsplit_mut
]: slice::rsplit_mut
``
938
945
`/// [slices]: slice
`
939
946
`#[stable(feature = "slice_rsplit", since = "1.27.0")]
`
``
947
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
940
948
`pub struct RSplitMut<'a, T: 'a, P>
`
941
949
`where
`
942
950
`P: FnMut(&T) -> bool,
`
`@@ -1059,6 +1067,7 @@ impl<T, I: SplitIter<Item = T>> Iterator for GenericSplitN {
`
1059
1067
`` /// [splitn
]: slice::splitn
``
1060
1068
`/// [slices]: slice
`
1061
1069
`#[stable(feature = "rust1", since = "1.0.0")]
`
``
1070
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
1062
1071
`pub struct SplitN<'a, T: 'a, P>
`
1063
1072
`where
`
1064
1073
`P: FnMut(&T) -> bool,
`
`@@ -1099,6 +1108,7 @@ where
`
1099
1108
`` /// [rsplitn
]: slice::rsplitn
``
1100
1109
`/// [slices]: slice
`
1101
1110
`#[stable(feature = "rust1", since = "1.0.0")]
`
``
1111
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
1102
1112
`pub struct RSplitN<'a, T: 'a, P>
`
1103
1113
`where
`
1104
1114
`P: FnMut(&T) -> bool,
`
`@@ -1138,6 +1148,7 @@ where
`
1138
1148
`` /// [splitn_mut
]: slice::splitn_mut
``
1139
1149
`/// [slices]: slice
`
1140
1150
`#[stable(feature = "rust1", since = "1.0.0")]
`
``
1151
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
1141
1152
`pub struct SplitNMut<'a, T: 'a, P>
`
1142
1153
`where
`
1143
1154
`P: FnMut(&T) -> bool,
`
`@@ -1178,6 +1189,7 @@ where
`
1178
1189
`` /// [rsplitn_mut
]: slice::rsplitn_mut
``
1179
1190
`/// [slices]: slice
`
1180
1191
`#[stable(feature = "rust1", since = "1.0.0")]
`
``
1192
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
1181
1193
`pub struct RSplitNMut<'a, T: 'a, P>
`
1182
1194
`where
`
1183
1195
`P: FnMut(&T) -> bool,
`
`@@ -1222,6 +1234,7 @@ forward_iterator! { RSplitNMut: T, &'a mut [T] }
`
1222
1234
`/// [slices]: slice
`
1223
1235
`#[derive(Debug)]
`
1224
1236
`#[stable(feature = "rust1", since = "1.0.0")]
`
``
1237
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
1225
1238
`pub struct Windows<'a, T: 'a> {
`
1226
1239
`v: &'a [T],
`
1227
1240
`size: NonZeroUsize,
`
`@@ -1370,6 +1383,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for Windows<'a, T> {
`
1370
1383
`/// [slices]: slice
`
1371
1384
`#[derive(Debug)]
`
1372
1385
`#[stable(feature = "rust1", since = "1.0.0")]
`
``
1386
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
1373
1387
`pub struct Chunks<'a, T: 'a> {
`
1374
1388
`v: &'a [T],
`
1375
1389
`chunk_size: usize,
`
`@@ -1553,6 +1567,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for Chunks<'a, T> {
`
1553
1567
`/// [slices]: slice
`
1554
1568
`#[derive(Debug)]
`
1555
1569
`#[stable(feature = "rust1", since = "1.0.0")]
`
``
1570
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
1556
1571
`pub struct ChunksMut<'a, T: 'a> {
`
1557
1572
`v: &'a mut [T],
`
1558
1573
`chunk_size: usize,
`
`@@ -1722,6 +1737,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for ChunksMut<'a, T> {
`
1722
1737
`/// [slices]: slice
`
1723
1738
`#[derive(Debug)]
`
1724
1739
`#[stable(feature = "chunks_exact", since = "1.31.0")]
`
``
1740
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
1725
1741
`pub struct ChunksExact<'a, T: 'a> {
`
1726
1742
`v: &'a [T],
`
1727
1743
`rem: &'a [T],
`
`@@ -1881,6 +1897,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for ChunksExact<'a, T> {
`
1881
1897
`/// [slices]: slice
`
1882
1898
`#[derive(Debug)]
`
1883
1899
`#[stable(feature = "chunks_exact", since = "1.31.0")]
`
``
1900
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
1884
1901
`pub struct ChunksExactMut<'a, T: 'a> {
`
1885
1902
`v: &'a mut [T],
`
1886
1903
`rem: &'a mut [T],
`
`@@ -2034,6 +2051,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for ChunksExactMut<'a, T> {
`
2034
2051
`/// [slices]: slice
`
2035
2052
`#[derive(Debug, Clone, Copy)]
`
2036
2053
`#[unstable(feature = "array_windows", issue = "75027")]
`
``
2054
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
2037
2055
`pub struct ArrayWindows<'a, T: 'a, const N: usize> {
`
2038
2056
`slice_head: *const T,
`
2039
2057
`num: usize,
`
`@@ -2156,6 +2174,7 @@ impl<T, const N: usize> ExactSizeIterator for ArrayWindows<'_, T, N> {
`
2156
2174
`/// [slices]: slice
`
2157
2175
`#[derive(Debug)]
`
2158
2176
`#[unstable(feature = "array_chunks", issue = "74985")]
`
``
2177
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
2159
2178
`pub struct ArrayChunks<'a, T: 'a, const N: usize> {
`
2160
2179
`iter: Iter<'a, [T; N]>,
`
2161
2180
`rem: &'a [T],
`
`@@ -2282,6 +2301,7 @@ unsafe impl<'a, T, const N: usize> TrustedRandomAccessNoCoerce for ArrayChunks<'
`
2282
2301
`/// [slices]: slice
`
2283
2302
`#[derive(Debug)]
`
2284
2303
`#[unstable(feature = "array_chunks", issue = "74985")]
`
``
2304
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
2285
2305
`pub struct ArrayChunksMut<'a, T: 'a, const N: usize> {
`
2286
2306
`iter: IterMut<'a, [T; N]>,
`
2287
2307
`rem: &'a mut [T],
`
`@@ -2396,6 +2416,7 @@ unsafe impl<'a, T, const N: usize> TrustedRandomAccessNoCoerce for ArrayChunksMu
`
2396
2416
`/// [slices]: slice
`
2397
2417
`#[derive(Debug)]
`
2398
2418
`#[stable(feature = "rchunks", since = "1.31.0")]
`
``
2419
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
2399
2420
`pub struct RChunks<'a, T: 'a> {
`
2400
2421
`v: &'a [T],
`
2401
2422
`chunk_size: usize,
`
`@@ -2569,6 +2590,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunks<'a, T> {
`
2569
2590
`/// [slices]: slice
`
2570
2591
`#[derive(Debug)]
`
2571
2592
`#[stable(feature = "rchunks", since = "1.31.0")]
`
``
2593
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
2572
2594
`pub struct RChunksMut<'a, T: 'a> {
`
2573
2595
`v: &'a mut [T],
`
2574
2596
`chunk_size: usize,
`
`@@ -2742,6 +2764,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunksMut<'a, T> {
`
2742
2764
`/// [slices]: slice
`
2743
2765
`#[derive(Debug)]
`
2744
2766
`#[stable(feature = "rchunks", since = "1.31.0")]
`
``
2767
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
2745
2768
`pub struct RChunksExact<'a, T: 'a> {
`
2746
2769
`v: &'a [T],
`
2747
2770
`rem: &'a [T],
`
`@@ -2905,6 +2928,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunksExact<'a, T> {
`
2905
2928
`/// [slices]: slice
`
2906
2929
`#[derive(Debug)]
`
2907
2930
`#[stable(feature = "rchunks", since = "1.31.0")]
`
``
2931
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
2908
2932
`pub struct RChunksExactMut<'a, T: 'a> {
`
2909
2933
`v: &'a mut [T],
`
2910
2934
`rem: &'a mut [T],
`
`@@ -3071,6 +3095,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for IterMut<'a, T> {
`
3071
3095
`` /// [group_by
]: slice::group_by
``
3072
3096
`/// [slices]: slice
`
3073
3097
`#[unstable(feature = "slice_group_by", issue = "80552")]
`
``
3098
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
3074
3099
`pub struct GroupBy<'a, T: 'a, P> {
`
3075
3100
`slice: &'a [T],
`
3076
3101
`predicate: P,
`
`@@ -3157,6 +3182,7 @@ impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for GroupBy<'a, T, P> {
`
3157
3182
`` /// [group_by_mut
]: slice::group_by_mut
``
3158
3183
`/// [slices]: slice
`
3159
3184
`#[unstable(feature = "slice_group_by", issue = "80552")]
`
``
3185
`+
#[must_use = "iterators are lazy and do nothing unless consumed"]
`
3160
3186
`pub struct GroupByMut<'a, T: 'a, P> {
`
3161
3187
`slice: &'a mut [T],
`
3162
3188
`predicate: P,
`