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

filter_next false positive #7561

Closed
crumblingstatue opened this issue Aug 12, 2021 · 3 comments · Fixed by #7562
Closed

filter_next false positive #7561

crumblingstatue opened this issue Aug 12, 2021 · 3 comments · Fixed by #7562
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@crumblingstatue
Copy link

crumblingstatue commented Aug 12, 2021

Lint name:
filter_next

I tried this code:

struct Foo;
impl Foo {
    fn filter(&self, _spec: i32) -> std::vec::IntoIter<i32> {
        unimplemented!()
    }
}

fn main() {
    let empty = Foo.filter(42).next().is_none();
    println!("{}", empty);
}

I expected to see this happen: Clippy doesn't suggest anything

Instead, this happened:
Clippy says this:

warning: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead
 --> src/main.rs:9:17
  |
9 |     let empty = Foo.filter(42).next().is_none();
  |                 ^^^^^^^^^^^^^^^^^^^^^ help: try this: `Foo.find(42)`
  |

There is no find method on Foo.

Meta

clippy 0.1.56 (ccffcaf 2021-08-11)

rustc 1.56.0-nightly (ccffcafd5 2021-08-11)
binary: rustc
commit-hash: ccffcafd55e58f769d4b0efc0064bf65e76998e4
commit-date: 2021-08-11
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 12.0.1
@crumblingstatue crumblingstatue 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 Aug 12, 2021
@xFrednet
Copy link
Member

xFrednet commented Aug 12, 2021

Thank you for the bug report 🙃. Seems like there is a check missing to make sure that the object actually implements Iterator.

@rustbot rustbot added good-first-issue These issues are a good way to get started with Clippy I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Aug 12, 2021
@dswij
Copy link
Member

dswij commented Aug 13, 2021

@rustbot claim

@crumblingstatue
Copy link
Author

That was a quick fix, thank you!

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 good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants