@@ -62,6 +62,7 @@ fn size_from_ptr<T>(_: *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 < T > ,
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<T> 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 < T > ,
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<I> {
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 ,
@@ -1539,6 +1553,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for Chunks<'a, T> {
1539
1553
/// [slices]: slice
1540
1554
#[ derive( Debug ) ]
1541
1555
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1556
+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
1542
1557
pub struct ChunksMut < ' a , T : ' a > {
1543
1558
v : & ' a mut [ T ] ,
1544
1559
chunk_size : usize ,
@@ -1707,6 +1722,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for ChunksMut<'a, T> {
1707
1722
/// [slices]: slice
1708
1723
#[ derive( Debug ) ]
1709
1724
#[ stable( feature = "chunks_exact" , since = "1.31.0" ) ]
1725
+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
1710
1726
pub struct ChunksExact < ' a , T : ' a > {
1711
1727
v : & ' a [ T ] ,
1712
1728
rem : & ' a [ T ] ,
@@ -1866,6 +1882,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for ChunksExact<'a, T> {
1866
1882
/// [slices]: slice
1867
1883
#[ derive( Debug ) ]
1868
1884
#[ stable( feature = "chunks_exact" , since = "1.31.0" ) ]
1885
+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
1869
1886
pub struct ChunksExactMut < ' a , T : ' a > {
1870
1887
v : & ' a mut [ T ] ,
1871
1888
rem : & ' a mut [ T ] ,
@@ -2019,6 +2036,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for ChunksExactMut<'a, T> {
2019
2036
/// [slices]: slice
2020
2037
#[ derive( Debug , Clone , Copy ) ]
2021
2038
#[ unstable( feature = "array_windows" , issue = "75027" ) ]
2039
+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
2022
2040
pub struct ArrayWindows < ' a , T : ' a , const N : usize > {
2023
2041
slice_head : * const T ,
2024
2042
num : usize ,
@@ -2141,6 +2159,7 @@ impl<T, const N: usize> ExactSizeIterator for ArrayWindows<'_, T, N> {
2141
2159
/// [slices]: slice
2142
2160
#[ derive( Debug ) ]
2143
2161
#[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2162
+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
2144
2163
pub struct ArrayChunks < ' a , T : ' a , const N : usize > {
2145
2164
iter : Iter < ' a , [ T ; N ] > ,
2146
2165
rem : & ' a [ T ] ,
@@ -2267,6 +2286,7 @@ unsafe impl<'a, T, const N: usize> TrustedRandomAccessNoCoerce for ArrayChunks<'
2267
2286
/// [slices]: slice
2268
2287
#[ derive( Debug ) ]
2269
2288
#[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2289
+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
2270
2290
pub struct ArrayChunksMut < ' a , T : ' a , const N : usize > {
2271
2291
iter : IterMut < ' a , [ T ; N ] > ,
2272
2292
rem : & ' a mut [ T ] ,
@@ -2381,6 +2401,7 @@ unsafe impl<'a, T, const N: usize> TrustedRandomAccessNoCoerce for ArrayChunksMu
2381
2401
/// [slices]: slice
2382
2402
#[ derive( Debug ) ]
2383
2403
#[ stable( feature = "rchunks" , since = "1.31.0" ) ]
2404
+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
2384
2405
pub struct RChunks < ' a , T : ' a > {
2385
2406
v : & ' a [ T ] ,
2386
2407
chunk_size : usize ,
@@ -2547,6 +2568,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunks<'a, T> {
2547
2568
/// [slices]: slice
2548
2569
#[ derive( Debug ) ]
2549
2570
#[ stable( feature = "rchunks" , since = "1.31.0" ) ]
2571
+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
2550
2572
pub struct RChunksMut < ' a , T : ' a > {
2551
2573
v : & ' a mut [ T ] ,
2552
2574
chunk_size : usize ,
@@ -2714,6 +2736,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunksMut<'a, T> {
2714
2736
/// [slices]: slice
2715
2737
#[ derive( Debug ) ]
2716
2738
#[ stable( feature = "rchunks" , since = "1.31.0" ) ]
2739
+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
2717
2740
pub struct RChunksExact < ' a , T : ' a > {
2718
2741
v : & ' a [ T ] ,
2719
2742
rem : & ' a [ T ] ,
@@ -2877,6 +2900,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunksExact<'a, T> {
2877
2900
/// [slices]: slice
2878
2901
#[ derive( Debug ) ]
2879
2902
#[ stable( feature = "rchunks" , since = "1.31.0" ) ]
2903
+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
2880
2904
pub struct RChunksExactMut < ' a , T : ' a > {
2881
2905
v : & ' a mut [ T ] ,
2882
2906
rem : & ' a mut [ T ] ,
@@ -3043,6 +3067,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for IterMut<'a, T> {
3043
3067
/// [`group_by`]: slice::group_by
3044
3068
/// [slices]: slice
3045
3069
#[ unstable( feature = "slice_group_by" , issue = "80552" ) ]
3070
+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
3046
3071
pub struct GroupBy < ' a , T : ' a , P > {
3047
3072
slice : & ' a [ T ] ,
3048
3073
predicate : P ,
@@ -3129,6 +3154,7 @@ impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for GroupBy<'a, T, P> {
3129
3154
/// [`group_by_mut`]: slice::group_by_mut
3130
3155
/// [slices]: slice
3131
3156
#[ unstable( feature = "slice_group_by" , issue = "80552" ) ]
3157
+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
3132
3158
pub struct GroupByMut < ' a , T : ' a , P > {
3133
3159
slice : & ' a mut [ T ] ,
3134
3160
predicate : P ,
0 commit comments