Skip to content

Useless _map variant #15199

Open
Open
@TomFryersMidsummer

Description

@TomFryersMidsummer

What it does

Finds places where find_map and filter_map are used, where find or filter would suffice. These are those with a closure argument |a| ... where a is not mutated and the only possible return values are None or Some(a).

Advantage

It's simpler.

Drawbacks

Determining the possible return values might be tricky, as might be determining whether a is mutated.

Example

                .find_map(|(i, j)| {
                    let [ri, rj] = regions.get_disjoint_mut([i, j]).unwrap();
                    ri.join(rj).then_some((i, j))
                })

Could be written as:

                .find(|(i, j)| {
                    let [ri, rj] = regions.get_disjoint_mut([i, j]).unwrap();
                    ri.join(rj)
                })

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