Skip to content

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

Closed
@DrAlta

Description

@DrAlta

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions