Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find_maps that could be simplified to find #8467

Closed
smoelius opened this issue Feb 24, 2022 · 0 comments · Fixed by #8489
Closed

find_maps that could be simplified to find #8467

smoelius opened this issue Feb 24, 2022 · 0 comments · Fixed by #8489
Labels
A-lint Area: New lints

Comments

@smoelius
Copy link
Contributor

smoelius commented Feb 24, 2022

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.

@smoelius smoelius added the A-lint Area: New lints label Feb 24, 2022
@bors bors closed this as completed in 6e211ea Mar 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant