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

Needless continue for match block #4077

Open
pickfire opened this issue May 10, 2019 · 3 comments · May be fixed by #13891
Open

Needless continue for match block #4077

pickfire opened this issue May 10, 2019 · 3 comments · May be fixed by #13891
Assignees
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages

Comments

@pickfire
Copy link
Contributor

pickfire commented May 10, 2019

tl;dr Fix simple needless continue

for _ in 0..1 {
    // do something
    continue;
}

Currently, needless_continue only checks possible removal of continue by reordering if-else block. One more simpler needless continue to be removed:

From https://github.com/Gymmasssorla/finshir/blob/eae5d0c6761f5558c8ed33ef098d8bd13a07e64f/src/testing/mod.rs#L124-L136

        for _ in 0..(failed_count.get() - 1) {
            match socket.write_all(portion) {
                Ok(_) => return SendPortionResult::Success,
                Err(err) => {
                    error!(
                        "Failed to send {} byte(s) >>> {}! Retrying the operation...",
                        helpers::cyan(portion.len()),
                        err
                    );
                    continue;
                }
            }
        }

Which continue can be dropped.

        for _ in 0..(failed_count.get() - 1) {
            match socket.write_all(portion) {
                Ok(_) => return SendPortionResult::Success,
                Err(err) => {
                    error!(
                        "Failed to send {} byte(s) >>> {}! Retrying the operation...",
                        helpers::cyan(portion.len()),
                        err
                    );
                }
            }
        }

One more in https://github.com/Gymmasssorla/finshir/blob/eae5d0c6761f5558c8ed33ef098d8bd13a07e64f/src/testing/mod.rs#L150-L164

What needs to be achieve here is to check if there are any continue at the end of each branches (including if-else and match blocks).

Possible code changes to clippy can probably be done in https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/needless_continue.rs#L374

@flip1995 flip1995 added the C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages label May 13, 2019
@Xaeroxe
Copy link
Contributor

Xaeroxe commented Jan 11, 2023

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e1f764cbed2b7227df7a748aa6a2b2dd

Similarly, any continue, conditional or not, which is the last statement of the loop it is in, is useless and should be omitted.

lengyijun added a commit to lengyijun/rust-clippy that referenced this issue Sep 21, 2023
lengyijun added a commit to lengyijun/rust-clippy that referenced this issue Sep 21, 2023
lengyijun added a commit to lengyijun/rust-clippy that referenced this issue Sep 21, 2023
lengyijun added a commit to lengyijun/rust-clippy that referenced this issue Sep 21, 2023
@lengyijun
Copy link
Contributor

@rustbot claim

lengyijun added a commit to lengyijun/rust-clippy that referenced this issue Sep 22, 2023
lengyijun added a commit to lengyijun/rust-clippy that referenced this issue Sep 22, 2023
lengyijun added a commit to lengyijun/rust-clippy that referenced this issue Sep 23, 2023
lengyijun added a commit to lengyijun/rust-clippy that referenced this issue Sep 24, 2023
lengyijun added a commit to lengyijun/rust-clippy that referenced this issue Sep 25, 2023
lengyijun added a commit to lengyijun/rust-clippy that referenced this issue Sep 25, 2023
lengyijun added a commit to lengyijun/rust-clippy that referenced this issue Sep 26, 2023
lengyijun added a commit to lengyijun/rust-clippy that referenced this issue Sep 26, 2023
profetia pushed a commit to profetia/rust-clippy that referenced this issue Dec 28, 2024
profetia pushed a commit to profetia/rust-clippy that referenced this issue Dec 28, 2024
@profetia
Copy link

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages
Projects
None yet
5 participants