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

Warn on loop-match-break, replace with while-let #118

Closed
Zarathustra30 opened this issue Jul 27, 2015 · 1 comment
Closed

Warn on loop-match-break, replace with while-let #118

Zarathustra30 opened this issue Jul 27, 2015 · 1 comment
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience.

Comments

@Zarathustra30
Copy link

Loop-match-break constructs like this snippet stolen from the benchmarks game:

loop {
    let bi = match bodies.next() {
        Some(bi) => bi,
        None => break
    };
    ...
}

can be replaced with a simple while let:

while let Some(bi) = bodies.next() {
    ...
}

Loop-match-breaks don't do anything bad, but they decrease readability and make control flow more confusing. Are there any cases where while-let would not suffice?

@llogiq
Copy link
Contributor

llogiq commented Jul 28, 2015

If there is something unrelated between the loop and the match.

Apart from that we may also want to detect the same thing with if-let instead of match.

@Manishearth Manishearth added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. A-lint Area: New lints labels Aug 11, 2015
birkenfeld added a commit to birkenfeld/rust-clippy that referenced this issue Aug 29, 2015
birkenfeld added a commit to birkenfeld/rust-clippy that referenced this issue Aug 30, 2015
@llogiq llogiq closed this as completed in b72ef5a Aug 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience.
Projects
None yet
Development

No branches or pull requests

3 participants