Skip to content

Commit bf2427b

Browse files
committed
Do not flatten match arm block with leading attributes
1 parent f84c399 commit bf2427b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

rustfmt-core/rustfmt-lib/src/matches.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::iter::repeat;
44

5-
use rustc_ast::{ast, ptr};
5+
use rustc_ast::{ast, attr::HasAttrs, ptr};
66
use rustc_span::{BytePos, Span};
77

88
use crate::comment::{combine_strs_with_missing_comments, rewrite_comment};
@@ -298,8 +298,16 @@ fn flatten_arm_body<'a>(
298298

299299
if let Some(ref block) = block_can_be_flattened(context, body) {
300300
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+
}
303311
} else {
304312
let cond_becomes_muti_line = opt_shape
305313
.and_then(|shape| rewrite_cond(context, expr, shape))

0 commit comments

Comments
 (0)