-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add semicolon inside/outside block lints #7564
Conversation
r? @flip1995 (rust-highfive has picked a reviewer for you, use r? to override) |
I don't really understand why the |
I believe that the pipeline rebases your change on the current master that might be the reason for the failing test. Have you tried rebasing your changes? 🙃 |
I refactored the
I think it might be a good idea to move the lint into the |
If it's 2 lints that contradict eachother, then they have to go into Another possibility would be to merge those 2 lints into one lint with a configuration option. But in any case, I see this as a I'm not sure what the better approach is here. I'm fine with continuing with 2 separate lints for now and make the final decision right before the PR is merged. Another thing I noticed when skimming this PR is that those 2 lints are in separate files / lint passes. I would expect that almost all of the code for those 2 lints could be shared, except for the final decision what lint should be triggered. So what's the motivation in splitting this up? |
declare_lint_pass!(SemicolonOutsideBlock => [SEMICOLON_OUTSIDE_BLOCK]); | ||
|
||
impl LateLintPass<'_> for SemicolonOutsideBlock { | ||
fn check_fn( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have to check a whole function here? Couldn't you just use check_block
and then get the parent stmt and check if it is a StmtKind::Semi
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but that way I would also suggest a semicolon after the block of an fn
, or a match arm. I tried finding out if the block belongs to such things via parent_iter
, but that didn't really work the way expected. I thought check_fn
makes a cleaner approach, as it only iterates over blocks that we're interested in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this approach is, that you will only be able to allow this lint at the function scope and not directly on the block.
Alright, I think the configuration sounds good. Also restriction sounds fair then.
Actually I didn't split them up because of a real reason, adding a configuration would also merge them as well. I initially wrote the |
I would like to see those two lints implemented in the same file and LintPass then. |
☔ The latest upstream changes (presumably #7604) made this pull request unmergeable. Please resolve the merge conflicts. |
ping from triage @1c3t3a. Can you have any updates on this? If you have any questions on this, feel free to ask us. |
@giraffate Hei there, I am still planning to implement this, but I probably won't have time to do so until October. Is that fine with you? Otherwise I am ok with someone taking over. |
Okay! |
ping from triage @1c3t3a. Can you have time to work on this? |
Also if you have any questions blocking you from continue working on this, don't hesitate to ask! |
@1c3t3a ping from triage. According the triage procedure, I'm closing this because 2 weeks have passed with no activity. If you have more time to work on this, feel free to reopen this. |
@1c3t3a Would you mind if I try to pick this PR up again bringing it over the finish line? |
Sure go ahead! I don't plan to work on this in the next time :) |
@rustbot label -S-inactive-closed |
This PR adds two new lints to clippy according to #7322. The two lints offer two flavors of the same thing: they check if for
()
returning blocks the semicolon is inside or outside the block and correct it if possible. At the moment thesemicolon_outside_block
lint fires in thedogfood
test..stderr
file)cargo test
passes locallycargo dev update_lints
cargo dev fmt
changelog:
Added two new lints according to #7322.
[`semicolon_inside_block`]
: Checks for a block with a()
returning expression if the semicolon is inside the block.[`semicolon_outside_block`]
: Checks for a block with a()
returning expression if the semicolon is outside the block.