1- use rustc_ast:: ast:: StmtKind ;
21use rustc_ast:: { ast, ptr} ;
32use rustc_span:: Span ;
43use thin_vec:: thin_vec;
@@ -108,10 +107,7 @@ fn get_inner_expr<'a>(
108107 if !needs_block ( block, prefix, context) {
109108 // block.stmts.len() == 1 except with `|| {{}}`;
110109 // https://github.com/rust-lang/rustfmt/issues/3844
111- if let Some ( expr) = iter_stmts_without_empty ( & block. stmts )
112- . next ( )
113- . and_then ( stmt_expr)
114- {
110+ if let Some ( expr) = iter_stmts_without_empty ( & block) . next ( ) . and_then ( stmt_expr) {
115111 return get_inner_expr ( expr, prefix, context) ;
116112 }
117113 }
@@ -120,8 +116,11 @@ fn get_inner_expr<'a>(
120116 expr
121117}
122118
123- fn iter_stmts_without_empty ( stmts : & [ ast:: Stmt ] ) -> impl Iterator < Item = & ast:: Stmt > {
124- stmts. iter ( ) . filter ( |x| !matches ! ( x. kind, StmtKind :: Empty ) )
119+ fn iter_stmts_without_empty ( block : & ast:: Block ) -> impl Iterator < Item = & ast:: Stmt > {
120+ block
121+ . stmts
122+ . iter ( )
123+ . filter ( |stmt| !matches ! ( stmt. kind, ast:: StmtKind :: Empty ) )
125124}
126125
127126// Figure out if a block is necessary.
@@ -131,7 +130,7 @@ fn needs_block(block: &ast::Block, prefix: &str, context: &RewriteContext<'_>) -
131130 } ) ;
132131
133132 is_unsafe_block ( block)
134- || iter_stmts_without_empty ( & block. stmts ) . count ( ) > 1
133+ || iter_stmts_without_empty ( & block) . count ( ) > 1
135134 || has_attributes
136135 || block_contains_comment ( context, block)
137136 || prefix. contains ( '\n' )
0 commit comments