Skip to content

unnecessary_find_map should see through then_some #11260

@Swatinem

Description

@Swatinem

Summary

It would be nice if Clippy could also warn me about using then_some in return of a find_map closure, like in this example:

std::iter::once(1).find_map(|n| (n > 1).then_some(n));

Lint Name

unnecessary_find_map

Reproducer

I tried this code:

    // warns
    std::iter::once(1).find_map(|n| if n > 1 { Some(n) } else { None });
    // does not
    std::iter::once(1).find_map(|n| (n > 1).then_some(n));
    // better solution
    std::iter::once(1).find(|n| *n > 1);

I expected to see this happen:

The unnecessary_find_map lint should flag the second example as well

Instead, this happened:

No warning is emitted

Version

No response

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions