RS.CLIPPY.BLOCKS_IN_CONDITIONS
Useless or complex blocks that can be eliminated in conditions
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: blocks_in_conditions. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for if and match conditions that use blocks containing an
expression, statements or conditions that use closures with blocks.
Why is this bad?
Style, using blocks in the condition makes it hard to read.
Examples
if { true } { /* ... */ }
if { let x = somefunc(); x } { /* ... */ }
match { let e = somefunc(); e } {
// ...
}
Use instead:
if true { /* ... */ }
let res = { let x = somefunc(); x };
if res { /* ... */ }
let res = { let e = somefunc(); e };
match res {
// ...
}
Past names
- block_in_if_condition_expr
- block_in_if_condition_stmt
- blocks_in_if_conditions