@@ -107,7 +107,10 @@ fn get_inner_expr<'a>(
107107 if !needs_block ( block, prefix, context) {
108108 // block.stmts.len() == 1 except with `|| {{}}`;
109109 // https://github.com/rust-lang/rustfmt/issues/3844
110- if let Some ( expr) = block. stmts . first ( ) . and_then ( stmt_expr) {
110+ if let Some ( expr) = iter_stmts_without_empty ( & block. stmts )
111+ . next ( )
112+ . and_then ( stmt_expr)
113+ {
111114 return get_inner_expr ( expr, prefix, context) ;
112115 }
113116 }
@@ -116,14 +119,23 @@ fn get_inner_expr<'a>(
116119 expr
117120}
118121
122+ fn iter_stmts_without_empty (
123+ stmts : & thin_vec:: ThinVec < ast:: Stmt > ,
124+ ) -> impl Iterator < Item = & ast:: Stmt > {
125+ stmts. iter ( ) . filter ( |x| match x. kind {
126+ crate :: ast:: StmtKind :: Empty => false ,
127+ _ => true ,
128+ } )
129+ }
130+
119131// Figure out if a block is necessary.
120132fn needs_block ( block : & ast:: Block , prefix : & str , context : & RewriteContext < ' _ > ) -> bool {
121133 let has_attributes = block. stmts . first ( ) . map_or ( false , |first_stmt| {
122134 !get_attrs_from_stmt ( first_stmt) . is_empty ( )
123135 } ) ;
124136
125137 is_unsafe_block ( block)
126- || block. stmts . len ( ) > 1
138+ || iter_stmts_without_empty ( & block. stmts ) . count ( ) > 1
127139 || has_attributes
128140 || block_contains_comment ( context, block)
129141 || prefix. contains ( '\n' )
0 commit comments