Skip to content

find_maps that could be simplified to find #8467

Closed
@smoelius

Description

@smoelius

What it does

Finds occurrences of find_map that could be simplified to find.

Lint Name

simplifiable_find_map(?)

Category

complexity

Advantage

Essentially the same benefits of the filter_next lint (in fact, this could perhaps be an enhancement of that lint).

Drawbacks

None(?).

Example

pub fn main() {
    let xs = [0, 1, 2];
    let odd = xs.iter().find_map(|x| if x % 2 == 1 { Some(x) } else { None });
    println!("{:?}", odd);
}

Could be written as:

pub fn main() {
    let xs = [0, 1, 2];
    let odd = xs.iter().find(|x| *x % 2 == 1);
    println!("{:?}", odd);
}

A tricky part could be that find's function argument expects a reference, but find's does not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions