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]: lint if the last stmt in for/while/loop is `co… #11546

Closed
wants to merge 1 commit into from

Conversation

lengyijun
Copy link
Contributor

@lengyijun lengyijun commented Sep 21, 2023

changelog: [needless_continue]: lint if the last stmt in for/while/loop is continue, recursively
Fixes: #4077

@rustbot
Copy link
Collaborator

rustbot commented Sep 21, 2023

r? @xFrednet

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 21, 2023
@lengyijun lengyijun force-pushed the needless_continue_last branch from 821e055 to a403969 Compare September 21, 2023 01:55
@Alexendoo
Copy link
Member

This would be another good one to look at @y21

@Alexendoo Alexendoo assigned Alexendoo and unassigned xFrednet Sep 21, 2023
Copy link
Member

@y21 y21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few things, other than that it looks good to me!

clippy_lints/src/needless_continue.rs Outdated Show resolved Hide resolved
clippy_lints/src/needless_continue.rs Outdated Show resolved Hide resolved
tests/ui/needless_continue.rs Show resolved Hide resolved
clippy_lints/src/needless_continue.rs Outdated Show resolved Hide resolved
@lengyijun lengyijun force-pushed the needless_continue_last branch from a403969 to 5493578 Compare September 22, 2023 12:39
Copy link
Member

@y21 y21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the lint description could also use an update now that it lints additional cases and no longer just if exprs.

clippy_lints/src/needless_continue.rs Outdated Show resolved Hide resolved
@lengyijun lengyijun force-pushed the needless_continue_last branch 2 times, most recently from 0bf5d42 to 4a45997 Compare September 23, 2023 04:45
@xFrednet
Copy link
Member

Hey @lengyijun, the CI failed on your last commit. Do you need any help to address the issue? :)

@lengyijun lengyijun force-pushed the needless_continue_last branch 3 times, most recently from 1d85d1b to d890421 Compare September 25, 2023 01:50
Copy link
Member

@y21 y21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@lengyijun lengyijun force-pushed the needless_continue_last branch from d890421 to a773ed0 Compare September 26, 2023 00:14
@lengyijun lengyijun force-pushed the needless_continue_last branch from a773ed0 to 9f999e9 Compare September 26, 2023 11:49
@Alexendoo
Copy link
Member

@bors delegate=y21

I think a good follow up to this if you're interested would be to split this lint up, this addition should be warn by default IMO but the lint is currently pedantic. The suggestions that require rearranging code instead of just removing a continue/else { continue } could go in their own lint

@bors
Copy link
Contributor

bors commented Sep 26, 2023

✌️ @y21, you can now approve this pull request!

If @Alexendoo told you to "r=me" after making some further change, please make that change, then do @bors r=@Alexendoo

Copy link
Member

@y21 y21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked through this one last time and found a potential edge case I wanted to mention (sorry! 😅)

}
};
check_last_stmt_in_block(loop_block, &p);

for (i, stmt) in loop_block.stmts.iter().enumerate() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now it's possible for the same lint to emit two warnings for the following code:

loop {
  if true {

  } else { // redundant `else`
    continue; // redundant `continue`
  }
}
Output
warning: this `continue` expression is redundant
   --> test.rs:171:13
    |
171 |             continue;
    |             ^^^^^^^^

warning: this `else` block is redundant
   --> test.rs:170:16
    |
170 |           } else {
    |  ________________^
171 | |             continue;
172 | |         }
    | |_________^
    |

I like the other warning a bit more in this case because it suggests removing the whole else block altogether.

@Alexendoo What do you think? Is this fine to ignore for now or would you consider it a potential blocker? Looks like it possibly has a bit of overlap with your suggestion to split up the lint

If this is a good idea and worth fixing in this PR, we could probably just move this check_last_stmt_in_expr call into the loop and guard it behind an i == stmts.len() - 1 check so that it only runs on the last statement, inline the with_if_expr function (it's really short and only used here, anyway) and add continue; in the one lint case that is emitted here so that it skips checking the new case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good catch, we don't want to be linting the same thing twice

The else winning would be preferable, but if it's easier implementation wise to ignore it that's fine too, there's a lint for empty else blocks that would pick it up

@Alexendoo Alexendoo added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Oct 16, 2023
@bors
Copy link
Contributor

bors commented Nov 10, 2023

☔ The latest upstream changes (presumably #11750) made this pull request unmergeable. Please resolve the merge conflicts.

@xFrednet
Copy link
Member

Hey @lengyijun, this is a ping from triage, since there hasn't been any activity in some time. Are you still planning to continue this implementation?

If you have any questions, you're always welcome to ask them in this PR or on Zulip.

@rustbot author

@xFrednet
Copy link
Member

Hey this is triage, I'm closing this due to inactivity. If you want to continue this implementation, you're welcome to create a new PR. Thank you for the time, you already put into this!

Interested parties are welcome to pick this implementation up as well :)

@rustbot label +S-inactive-closed -S-waiting-on-author -S-waiting-on-review

@xFrednet xFrednet closed this Jun 20, 2024
@rustbot rustbot added S-inactive-closed Status: Closed due to inactivity and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive-closed Status: Closed due to inactivity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Needless continue for match block
6 participants