diff options
| author | Caleb Cartwright <caleb.cartwright@outlook.com> | 2021-01-06 20:25:11 -0600 |
|---|---|---|
| committer | Caleb Cartwright <calebcartwright@users.noreply.github.com> | 2021-01-27 20:58:42 -0600 |
| commit | bd4dc36c4eb73a776143d51d15770d3060954d28 (patch) | |
| tree | 1f812b0ef9f8cca4169850b60d15fa3446bf09f5 /src/expr.rs | |
| parent | 3e613267161912f81e30fc413584e97b3e9c494a (diff) | |
refactor: cleanup block check for statements
Diffstat (limited to 'src/expr.rs')
| -rw-r--r-- | src/expr.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/expr.rs b/src/expr.rs index 71446ce1ab0..9c5876ce647 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1173,6 +1173,13 @@ pub(crate) fn is_simple_block_stmt( && attrs.map_or(true, |a| a.is_empty()) } +fn block_has_statements(block: &ast::Block) -> bool { + block + .stmts + .iter() + .any(|stmt| !matches!(stmt.kind, ast::StmtKind::Empty)) +} + /// Checks whether a block contains no statements, expressions, comments, or /// inner attributes. pub(crate) fn is_empty_block( @@ -1180,7 +1187,7 @@ pub(crate) fn is_empty_block( block: &ast::Block, attrs: Option<&[ast::Attribute]>, ) -> bool { - block.stmts.is_empty() + !block_has_statements(&block) && !block_contains_comment(context, block) && attrs.map_or(true, |a| inner_attributes(a).is_empty()) } |
