-
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-outside/inside-block lints #9826
Conversation
r? @Alexendoo (rust-highfive has picked a reviewer for you, use r? to override) |
f1a5d8e
to
d0a8c69
Compare
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_block
andsemicolon_inside_block
lintsFixes #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.