-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have
Description
Lint name: while_let_on_iterator
I tried this code:
fn parse_value<V>(tokens: TokenStream) -> parse::Result<(ValueExpr<V>, TokenStream)>
where
ValueExpr<V>: Parse,
{
let mut it = tokens.into_iter();
let mut value = TokenStream::new();
while let Some(tt) = it.next() {
if let TokenTree::Punct(p) = &tt {
if p.as_char() == ',' {
break;
}
}
value.append(tt);
}
Ok((ValueExpr::parse.parse2(value)?, it.collect()))
}
I expected to see this happen:
This should not trigger the lint because the iterator is used again after the loop. The purpose of explicitly calling next()
is to make it clear that the iterator may not be fully consumed in the loop and the remaining items can be processed elsewhere.
Instead, this happened: The lint triggers and tells me to use a for
loop.
Meta
Rust version (rustc -Vv
):
rustc 1.55.0 (c8dfcfe04 2021-09-06)
binary: rustc
commit-hash: c8dfcfe046a7680554bf4eb612bad840e7631c4b
commit-date: 2021-09-06
host: x86_64-apple-darwin
release: 1.55.0
LLVM version: 12.0.1
MattX
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't have