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

Lint Idea: Convert for loop and break to if let and find #4342

Open
ghost opened this issue Aug 6, 2019 · 1 comment
Open

Lint Idea: Convert for loop and break to if let and find #4342

ghost opened this issue Aug 6, 2019 · 1 comment
Labels
A-lint Area: New lints L-complexity Lint: Belongs in the complexity lint group L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@ghost
Copy link

ghost commented Aug 6, 2019

name: find_as_loop (Maybe. I'm not sure of this.)
group: pedantic

for x in &collection {
    if <condition> {
        <statemetns>;
        break;
    }
}

can be converted to

if let Some(x) = collection.iter().find(<condition>) {
    <statements>;
}
@flip1995 flip1995 added L-complexity Lint: Belongs in the complexity lint group L-suggestion Lint: Improving, adding or fixing lint suggestions A-lint Area: New lints labels Aug 6, 2019
@killercup
Copy link
Member

Also see #2401 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints L-complexity Lint: Belongs in the complexity lint group L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

No branches or pull requests

2 participants