Skip to content

Commit 4a053f2

Browse files
davidlattimorecalebcartwright
authored andcommitted
Do not flatten match arm block with leading attributes
This is a backport of #4124. Fixes #4109
1 parent f935f0c commit 4a053f2

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

Diff for: src/matches.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,11 @@ fn flatten_arm_body<'a>(
322322
if let Some(block) = block_can_be_flattened(context, body) {
323323
if let ast::StmtKind::Expr(ref expr) = block.stmts[0].kind {
324324
if let ast::ExprKind::Block(..) = expr.kind {
325-
flatten_arm_body(context, expr, None)
325+
if expr.attrs.is_empty() {
326+
flatten_arm_body(context, expr, None)
327+
} else {
328+
(true, body)
329+
}
326330
} else {
327331
let cond_becomes_muti_line = opt_shape
328332
.and_then(|shape| rewrite_cond(context, expr, shape))

Diff for: tests/source/match.rs

+19
Original file line numberDiff line numberDiff line change
@@ -568,3 +568,22 @@ fn issue_3774() {
568568
}
569569
}
570570
}
571+
572+
// #4109
573+
fn issue_4109() {
574+
match () {
575+
_ => {
576+
#[cfg(debug_assertions)]
577+
{
578+
println!("Foo");
579+
}
580+
}
581+
}
582+
583+
match () {
584+
_ => {
585+
#[allow(unsafe_code)]
586+
unsafe {}
587+
}
588+
}
589+
}

Diff for: tests/target/match.rs

+19
Original file line numberDiff line numberDiff line change
@@ -608,3 +608,22 @@ fn issue_3774() {
608608
}
609609
}
610610
}
611+
612+
// #4109
613+
fn issue_4109() {
614+
match () {
615+
_ => {
616+
#[cfg(debug_assertions)]
617+
{
618+
println!("Foo");
619+
}
620+
}
621+
}
622+
623+
match () {
624+
_ => {
625+
#[allow(unsafe_code)]
626+
unsafe {}
627+
}
628+
}
629+
}

0 commit comments

Comments
 (0)