Skip to content

Commit 344a3f8

Browse files
committed
Mark into_iter as #[must_use]
`into_iter` serves no function if not iterated over. If it's being used just to consume `self`, that would be better served by `drop`.
1 parent 198328a commit 344a3f8

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

library/core/src/iter/traits/collect.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ pub trait IntoIterator {
306306
/// assert_eq!(None, iter.next());
307307
/// ```
308308
#[lang = "into_iter"]
309+
#[must_use = "Iterators do nothing unless iterated over"]
309310
#[stable(feature = "rust1", since = "1.0.0")]
310311
fn into_iter(self) -> Self::IntoIter;
311312
}

library/coretests/tests/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ fn iterator_drops() {
193193
// Simple: drop new iterator.
194194
let i = Cell::new(0);
195195
{
196-
IntoIterator::into_iter(five(&i));
196+
drop(IntoIterator::into_iter(five(&i)));
197197
}
198198
assert_eq!(i.get(), 5);
199199

0 commit comments

Comments
 (0)