Skip to content

manual_filter triggered if you return Some(-x) #10125

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

Closed
DrAlta opened this issue Dec 29, 2022 · 2 comments
Closed

manual_filter triggered if you return Some(-x) #10125

DrAlta opened this issue Dec 29, 2022 · 2 comments
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

Comments

@DrAlta
Copy link

DrAlta commented Dec 29, 2022

Summary

I'm getting error: manual implementation of `Option::filter` even though the code isn't filtering as it return Some(-x) not Some(x)

Lint Name

manual_filter

Reproducer

I tried this code:

                if let Some(n) = r.numer().to_i64() {
                    if sign == Sign::Minus {
                        Some(-n)
                    } else {
                        Some(n)
                    }
                } else {
                    None
                }

I saw this happen:

error: manual implementation of `Option::filter`
Error:    --> src/fraction/generic_fraction.rs:688:17
    |
688 | /                 if let Some(n) = r.numer().to_i64() {
689 | |                     if sign == Sign::Minus {
690 | |                         Some(-n)
691 | |                     } else {
...   |
695 | |                     None
696 | |                 }
    | |_________________^ help: try this: `r.numer().to_i64().filter(|&n| sign != Sign::Minus)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_filter
    = note: `-D clippy::manual-filter` implied by `-D warnings`

I expected to see this happen:
It to find nothing wrong like it did before I updated Clippy

Version

rustc 1.66.0 (69f9c33d7 2022-12-12)
binary: rustc
commit-hash: 69f9c33d71c871fc16ac445211281c6e7a340943
commit-date: 2022-12-12
host: x86_64-unknown-linux-gnu
release: 1.66.0
LLVM version: 15.0.2

Additional Labels

No response

@DrAlta DrAlta 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 Dec 29, 2022
@koka831
Copy link
Contributor

koka831 commented Dec 29, 2022

It looks similar to #10088, which will be fixed in #10091.

@xFrednet
Copy link
Member

Thank you for the issue! I'm closing this due to the comment from @koka831. Thank you for the contribution you two!

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
Projects
None yet
Development

No branches or pull requests

3 participants