Skip to content

Commit bd4dc36

Browse files
refactor: cleanup block check for statements
1 parent 3e61326 commit bd4dc36

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/expr.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1173,14 +1173,21 @@ pub(crate) fn is_simple_block_stmt(
11731173
&& attrs.map_or(true, |a| a.is_empty())
11741174
}
11751175

1176+
fn block_has_statements(block: &ast::Block) -> bool {
1177+
block
1178+
.stmts
1179+
.iter()
1180+
.any(|stmt| !matches!(stmt.kind, ast::StmtKind::Empty))
1181+
}
1182+
11761183
/// Checks whether a block contains no statements, expressions, comments, or
11771184
/// inner attributes.
11781185
pub(crate) fn is_empty_block(
11791186
context: &RewriteContext<'_>,
11801187
block: &ast::Block,
11811188
attrs: Option<&[ast::Attribute]>,
11821189
) -> bool {
1183-
block.stmts.is_empty()
1190+
!block_has_statements(&block)
11841191
&& !block_contains_comment(context, block)
11851192
&& attrs.map_or(true, |a| inner_attributes(a).is_empty())
11861193
}

0 commit comments

Comments
 (0)