Add semicolon-outside/inside-block lints#9826
Conversation
|
r? @Alexendoo (rust-highfive has picked a reviewer for you, use r? to override) |
f1a5d8e to
d0a8c69
Compare
|
☔ The latest upstream changes (presumably #9924) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Needed to rebase, changes are in 16b016e |
clippy_lints/src/semicolon_block.rs
Outdated
| declare_clippy_lint! { | ||
| /// ### What it does | ||
| /// | ||
| /// For () returning expressions, check that the semicolon is inside the block. |
There was a problem hiding this comment.
Thanks! I think this is the last thing:
I believe this lint would apply to expressions returning any type rather than just ()
There was a problem hiding this comment.
Ah, I forgot to change that good catch. Unsure what wording to take here though, let me know if this works.
There was a problem hiding this comment.
It's tricky, maybe something like "Suggests moving the semicolon from a block's final expression outside of the block" and the opposite, to me the current reading suggests it wouldn't work on things like { a; b; }
There was a problem hiding this comment.
You can rebase on master also to fix the remark CI issue
clippy_lints/src/semicolon_block.rs
Outdated
| declare_clippy_lint! { | ||
| /// ### What it does | ||
| /// | ||
| /// Suggests moving the semicolon from a block inside of the block to its kast expression. |
There was a problem hiding this comment.
| /// Suggests moving the semicolon from a block inside of the block to its kast expression. | |
| /// Suggests moving the semicolon after a block to the inside of the block, after its last expression. |
There was a problem hiding this comment.
Sorry, I was a bit hasty on that commit I think, fixed it
|
If I read correctly, this lint doesn't trigger if both semicolons are used, yes? |
|
It does not trigger in that case no (I added it as to the tests though, thanks for bringing that up) |
|
@bors r=Alexendoo |
|
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
I think the double semicolon case perfectly fits the lint name Also I'd expect the following cases to be warn-by-default. unsafe { foo(); }; // Double semicolon.
match foo() { _ => foo() }; // The arm returns `()`.
match foo() { _ => foo(), _ => { foo() } }; // All arms return `()`.
for _ in [()] { unit_fn_block()/*semi or no semi*/ }; // Always `()`.
if foo() { unit_fn_block()/*semi or no semi*/ }; // Always `()`.
loop { }; // `!`If we want to warn these cases, while still make it configurable for |
|
🤔 If the current semicolon-outside/inside-block behaviors rely purely on the syntax, and |
|
Changing |
Oh, I forget the drop order stuff. |
changelog: Add
semicolon_outside_blockandsemicolon_inside_blocklintsFixes #7322
An earlier attempt at this can be found here #7564. This PR still implements two separate lints but I am open to merging them into a single one that's configurable.