Skip to content

Needless continue for match block #4077

Closed
@pickfire

Description

@pickfire

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

Metadata

Metadata

Assignees

Labels

C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messages

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions