Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

needless_collect false positive #7512

Open
SamRodri opened this issue Jul 29, 2021 · 1 comment
Open

needless_collect false positive #7512

SamRodri opened this issue Jul 29, 2021 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have L-nursery Lint: Currently in the nursery group

Comments

@SamRodri
Copy link

Lint name: needless_collect

Reduced code:

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.

Meta

  • cargo clippy -V: clippy 0.1.54 (a178d032 2021-07-26)
  • rustc -Vv:
rustc 1.54.0 (a178d0322 2021-07-26)
binary: rustc
commit-hash: a178d0322ce20e33eac124758e837cbd80a6f633
commit-date: 2021-07-26
host: x86_64-pc-windows-msvc
release: 1.54.0
LLVM version: 12.0.1
@SamRodri SamRodri added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jul 29, 2021
@sophiajt
Copy link
Contributor

sophiajt commented Jul 29, 2021

Just coming here to +1 this. We're having to disable this lint globally in Nushell because of the number of false positives.

Similar issue reported earlier: #7336

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have L-nursery Lint: Currently in the nursery group
Projects
None yet
Development

No branches or pull requests

3 participants