Skip to content

Commit 31aa213

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 31aa213

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
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

tests/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn call<F>(f: F) where F : Fn() {
99
fn main() {
1010
let y = vec![format!("World")];
1111
call(|| {
12-
y.into_iter();
12+
let _ = y.into_iter();
1313
//~^ ERROR cannot move out of `y`, a captured variable in an `Fn` closure
1414
});
1515
}

0 commit comments

Comments
 (0)