rust-lang / rust-lang/rust-clippy

`manual_filter` FN when the filter is further mapped

Open
#16,776 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-negative
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the manual_filter lint implementation and its existing tests, then run the provided Option<usize> reproducer to confirm the missing diagnostic. Trace how the lint recognizes the Some(n) branch and add a regression test covering Some(n + 1); done means the match is diagnosed with the appropriate filter_map or Option::and_then suggestion.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.