File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
rustfmt-core/rustfmt-lib/src Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
use std:: iter:: repeat;
4
4
5
- use rustc_ast:: { ast, ptr} ;
5
+ use rustc_ast:: { ast, attr :: HasAttrs , ptr} ;
6
6
use rustc_span:: { BytePos , Span } ;
7
7
8
8
use crate :: comment:: { combine_strs_with_missing_comments, rewrite_comment} ;
@@ -298,8 +298,16 @@ fn flatten_arm_body<'a>(
298
298
299
299
if let Some ( ref block) = block_can_be_flattened ( context, body) {
300
300
if let ast:: StmtKind :: Expr ( ref expr) = block. stmts [ 0 ] . kind {
301
- if let ast:: ExprKind :: Block ( ..) = expr. kind {
302
- flatten_arm_body ( context, expr, None )
301
+ if let ast:: ExprKind :: Block ( ref b, _) = expr. kind {
302
+ if expr. attrs . is_empty ( )
303
+ && b. stmts
304
+ . first ( )
305
+ . map_or ( false , |stmt| stmt. attrs ( ) . is_empty ( ) )
306
+ {
307
+ flatten_arm_body ( context, expr, None )
308
+ } else {
309
+ ( true , body)
310
+ }
303
311
} else {
304
312
let cond_becomes_muti_line = opt_shape
305
313
. and_then ( |shape| rewrite_cond ( context, expr, shape) )
You can’t perform that action at this time.
0 commit comments