@@ -62,6 +62,7 @@ fn size_from_ptr<T>(_: *const T) -> usize {
6262/// [`iter`]: slice::iter
6363/// [slices]: slice
6464#[ stable( feature = "rust1" , since = "1.0.0" ) ]
65+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
6566pub struct Iter < ' a , T : ' a > {
6667 ptr : NonNull < T > ,
6768 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> {
182183/// [`iter_mut`]: slice::iter_mut
183184/// [slices]: slice
184185#[ stable( feature = "rust1" , since = "1.0.0" ) ]
186+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
185187pub struct IterMut < ' a , T : ' a > {
186188 ptr : NonNull < T > ,
187189 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 {
339341/// [`split`]: slice::split
340342/// [slices]: slice
341343#[ stable( feature = "rust1" , since = "1.0.0" ) ]
344+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
342345pub struct Split < ' a , T : ' a , P >
343346where
344347 P : FnMut ( & T ) -> bool ,
@@ -469,6 +472,7 @@ impl<T, P> FusedIterator for Split<'_, T, P> where P: FnMut(&T) -> bool {}
469472/// [`split_inclusive`]: slice::split_inclusive
470473/// [slices]: slice
471474#[ stable( feature = "split_inclusive" , since = "1.51.0" ) ]
475+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
472476pub struct SplitInclusive < ' a , T : ' a , P >
473477where
474478 P : FnMut ( & T ) -> bool ,
@@ -589,6 +593,7 @@ impl<T, P> FusedIterator for SplitInclusive<'_, T, P> where P: FnMut(&T) -> bool
589593/// [`split_mut`]: slice::split_mut
590594/// [slices]: slice
591595#[ stable( feature = "rust1" , since = "1.0.0" ) ]
596+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
592597pub struct SplitMut < ' a , T : ' a , P >
593598where
594599 P : FnMut ( & T ) -> bool ,
@@ -718,6 +723,7 @@ impl<T, P> FusedIterator for SplitMut<'_, T, P> where P: FnMut(&T) -> bool {}
718723/// [`split_inclusive_mut`]: slice::split_inclusive_mut
719724/// [slices]: slice
720725#[ stable( feature = "split_inclusive" , since = "1.51.0" ) ]
726+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
721727pub struct SplitInclusiveMut < ' a , T : ' a , P >
722728where
723729 P : FnMut ( & T ) -> bool ,
@@ -841,6 +847,7 @@ impl<T, P> FusedIterator for SplitInclusiveMut<'_, T, P> where P: FnMut(&T) -> b
841847/// [`rsplit`]: slice::rsplit
842848/// [slices]: slice
843849#[ stable( feature = "slice_rsplit" , since = "1.27.0" ) ]
850+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
844851pub struct RSplit < ' a , T : ' a , P >
845852where
846853 P : FnMut ( & T ) -> bool ,
@@ -937,6 +944,7 @@ impl<T, P> FusedIterator for RSplit<'_, T, P> where P: FnMut(&T) -> bool {}
937944/// [`rsplit_mut`]: slice::rsplit_mut
938945/// [slices]: slice
939946#[ stable( feature = "slice_rsplit" , since = "1.27.0" ) ]
947+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
940948pub struct RSplitMut < ' a , T : ' a , P >
941949where
942950 P : FnMut ( & T ) -> bool ,
@@ -1059,6 +1067,7 @@ impl<T, I: SplitIter<Item = T>> Iterator for GenericSplitN<I> {
10591067/// [`splitn`]: slice::splitn
10601068/// [slices]: slice
10611069#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1070+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
10621071pub struct SplitN < ' a , T : ' a , P >
10631072where
10641073 P : FnMut ( & T ) -> bool ,
@@ -1099,6 +1108,7 @@ where
10991108/// [`rsplitn`]: slice::rsplitn
11001109/// [slices]: slice
11011110#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1111+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
11021112pub struct RSplitN < ' a , T : ' a , P >
11031113where
11041114 P : FnMut ( & T ) -> bool ,
@@ -1138,6 +1148,7 @@ where
11381148/// [`splitn_mut`]: slice::splitn_mut
11391149/// [slices]: slice
11401150#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1151+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
11411152pub struct SplitNMut < ' a , T : ' a , P >
11421153where
11431154 P : FnMut ( & T ) -> bool ,
@@ -1178,6 +1189,7 @@ where
11781189/// [`rsplitn_mut`]: slice::rsplitn_mut
11791190/// [slices]: slice
11801191#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1192+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
11811193pub struct RSplitNMut < ' a , T : ' a , P >
11821194where
11831195 P : FnMut ( & T ) -> bool ,
@@ -1222,6 +1234,7 @@ forward_iterator! { RSplitNMut: T, &'a mut [T] }
12221234/// [slices]: slice
12231235#[ derive( Debug ) ]
12241236#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1237+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
12251238pub struct Windows < ' a , T : ' a > {
12261239 v : & ' a [ T ] ,
12271240 size : NonZeroUsize ,
@@ -1370,6 +1383,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for Windows<'a, T> {
13701383/// [slices]: slice
13711384#[ derive( Debug ) ]
13721385#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1386+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
13731387pub struct Chunks < ' a , T : ' a > {
13741388 v : & ' a [ T ] ,
13751389 chunk_size : usize ,
@@ -1553,6 +1567,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for Chunks<'a, T> {
15531567/// [slices]: slice
15541568#[ derive( Debug ) ]
15551569#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1570+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
15561571pub struct ChunksMut < ' a , T : ' a > {
15571572 v : & ' a mut [ T ] ,
15581573 chunk_size : usize ,
@@ -1722,6 +1737,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for ChunksMut<'a, T> {
17221737/// [slices]: slice
17231738#[ derive( Debug ) ]
17241739#[ stable( feature = "chunks_exact" , since = "1.31.0" ) ]
1740+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
17251741pub struct ChunksExact < ' a , T : ' a > {
17261742 v : & ' a [ T ] ,
17271743 rem : & ' a [ T ] ,
@@ -1881,6 +1897,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for ChunksExact<'a, T> {
18811897/// [slices]: slice
18821898#[ derive( Debug ) ]
18831899#[ stable( feature = "chunks_exact" , since = "1.31.0" ) ]
1900+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
18841901pub struct ChunksExactMut < ' a , T : ' a > {
18851902 v : & ' a mut [ T ] ,
18861903 rem : & ' a mut [ T ] ,
@@ -2034,6 +2051,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for ChunksExactMut<'a, T> {
20342051/// [slices]: slice
20352052#[ derive( Debug , Clone , Copy ) ]
20362053#[ unstable( feature = "array_windows" , issue = "75027" ) ]
2054+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
20372055pub struct ArrayWindows < ' a , T : ' a , const N : usize > {
20382056 slice_head : * const T ,
20392057 num : usize ,
@@ -2156,6 +2174,7 @@ impl<T, const N: usize> ExactSizeIterator for ArrayWindows<'_, T, N> {
21562174/// [slices]: slice
21572175#[ derive( Debug ) ]
21582176#[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2177+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
21592178pub struct ArrayChunks < ' a , T : ' a , const N : usize > {
21602179 iter : Iter < ' a , [ T ; N ] > ,
21612180 rem : & ' a [ T ] ,
@@ -2282,6 +2301,7 @@ unsafe impl<'a, T, const N: usize> TrustedRandomAccessNoCoerce for ArrayChunks<'
22822301/// [slices]: slice
22832302#[ derive( Debug ) ]
22842303#[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2304+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
22852305pub struct ArrayChunksMut < ' a , T : ' a , const N : usize > {
22862306 iter : IterMut < ' a , [ T ; N ] > ,
22872307 rem : & ' a mut [ T ] ,
@@ -2396,6 +2416,7 @@ unsafe impl<'a, T, const N: usize> TrustedRandomAccessNoCoerce for ArrayChunksMu
23962416/// [slices]: slice
23972417#[ derive( Debug ) ]
23982418#[ stable( feature = "rchunks" , since = "1.31.0" ) ]
2419+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
23992420pub struct RChunks < ' a , T : ' a > {
24002421 v : & ' a [ T ] ,
24012422 chunk_size : usize ,
@@ -2569,6 +2590,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunks<'a, T> {
25692590/// [slices]: slice
25702591#[ derive( Debug ) ]
25712592#[ stable( feature = "rchunks" , since = "1.31.0" ) ]
2593+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
25722594pub struct RChunksMut < ' a , T : ' a > {
25732595 v : & ' a mut [ T ] ,
25742596 chunk_size : usize ,
@@ -2742,6 +2764,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunksMut<'a, T> {
27422764/// [slices]: slice
27432765#[ derive( Debug ) ]
27442766#[ stable( feature = "rchunks" , since = "1.31.0" ) ]
2767+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
27452768pub struct RChunksExact < ' a , T : ' a > {
27462769 v : & ' a [ T ] ,
27472770 rem : & ' a [ T ] ,
@@ -2905,6 +2928,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for RChunksExact<'a, T> {
29052928/// [slices]: slice
29062929#[ derive( Debug ) ]
29072930#[ stable( feature = "rchunks" , since = "1.31.0" ) ]
2931+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
29082932pub struct RChunksExactMut < ' a , T : ' a > {
29092933 v : & ' a mut [ T ] ,
29102934 rem : & ' a mut [ T ] ,
@@ -3071,6 +3095,7 @@ unsafe impl<'a, T> TrustedRandomAccessNoCoerce for IterMut<'a, T> {
30713095/// [`group_by`]: slice::group_by
30723096/// [slices]: slice
30733097#[ unstable( feature = "slice_group_by" , issue = "80552" ) ]
3098+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
30743099pub struct GroupBy < ' a , T : ' a , P > {
30753100 slice : & ' a [ T ] ,
30763101 predicate : P ,
@@ -3157,6 +3182,7 @@ impl<'a, T: 'a + fmt::Debug, P> fmt::Debug for GroupBy<'a, T, P> {
31573182/// [`group_by_mut`]: slice::group_by_mut
31583183/// [slices]: slice
31593184#[ unstable( feature = "slice_group_by" , issue = "80552" ) ]
3185+ #[ must_use = "iterators are lazy and do nothing unless consumed" ]
31603186pub struct GroupByMut < ' a , T : ' a , P > {
31613187 slice : & ' a mut [ T ] ,
31623188 predicate : P ,
0 commit comments