Skip to content

manual_filter FN when the filter is further mapped #16776

@profetia

Description

@profetia

Summary

manual_filter will work for the following:

match v {
    Some(n) => {
        if n > 10 {
            Some(n)
        } else {
            None
        }
    }
    None => None,
}

However, if we change Some(n) to Some(n + 1), it will not. For this case, the preferable behavior might be suggesting to use filter_map, i.e. Option::and_then instead.

Lint Name

manual_filter

Reproducer

I tried this code:

fn maunal_filter_and_then(v: Option<usize>) -> Option<usize> {
    match v {
        Some(n) => {
            if n > 10 {
                Some(n + 1)
            } else {
                None
            }
        }
        None => None,
    }
}

I expected to see this happen:
Lint on the match

Instead, this happened:
Nothing

Version

rustc 1.96.0-nightly (ac7f9ec7d 2026-03-20)
binary: rustc
commit-hash: ac7f9ec7da74d37fd28667c86bf117a39ba5b02a
commit-date: 2026-03-20
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions