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

Lint to warn on empty blocks #10868

Closed
Centri3 opened this issue Jun 2, 2023 · 1 comment · Fixed by #10921
Closed

Lint to warn on empty blocks #10868

Centri3 opened this issue Jun 2, 2023 · 1 comment · Fixed by #10921
Assignees
Labels
A-lint Area: New lints

Comments

@Centri3
Copy link
Member

Centri3 commented Jun 2, 2023

What it does

Emits a warning on empty blocks (no statements nor an expression).

Advantage

This is always unnecessary (afaik), and even on the off chance it mutates something else (like potentially in the condition for an if), the if can be entirely removed, leaving just the condition.

Drawbacks

None

Example

if i_mutate_a_variable(&mut owo) {}
let _x = {};

Could be written as:

i_mutate_a_variable(&mut owo);
// <removed>
@Centri3 Centri3 added the A-lint Area: New lints label Jun 2, 2023
@Centri3
Copy link
Member Author

Centri3 commented Jun 4, 2023

I feel like this could be turned into more specific lints, as an example of one, needless_if similar to needless_else, but for if <expr> {} instead (suggesting to omit the if altogether, and only have <expr>).

It's worth noting though that many cases will likely require an empty block, so a catchall can't really be used (except for maybe a block on its own, not part of an if statement or anything)

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant