pub struct Foo {
foo: bool,
bar: bool,
}
pub fn test(foo: Vec<Foo>) {
let bar: Vec<_> = foo.iter().map(|f|f.bar).collect();
drop(foo);
for (_, _) in bar.into_iter().enumerate() {
}
}
// pub fn incorrect_suggestion(foo: Vec<Foo>) {
//
// drop(foo);
//
// for (_, _) in foo.iter().map(|f|f.bar).enumerate() {
//
// }
// }
I expected no warning here because foo is dropped. The incorrect suggestion also appears if foo is shadowed, potentially generating incorrect code that compiles.
Lint name:
needless_collect
Reduced code:
I expected no warning here because
foo
is dropped. The incorrect suggestion also appears iffoo
is shadowed, potentially generating incorrect code that compiles.Meta
cargo clippy -V
: clippy 0.1.54 (a178d032 2021-07-26)rustc -Vv
: