diff --git a/src/matches.rs b/src/matches.rs index c3102f12123..c09949cf2e8 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -263,7 +263,7 @@ fn rewrite_match_arm( false, )?; - let arrow_span = mk_sp(arm.pats.last().unwrap().span.hi(), arm.body.span.lo()); + let arrow_span = mk_sp(arm.pats.last().unwrap().span.hi(), arm.body.span().lo()); rewrite_match_body( context, &arm.body, @@ -364,7 +364,8 @@ fn rewrite_match_body( shape.indent }; - let forbid_same_line = has_guard && pats_str.contains('\n') && !is_empty_block; + let forbid_same_line = + (has_guard && pats_str.contains('\n') && !is_empty_block) || !body.attrs.is_empty(); // Look for comments between `=>` and the start of the body. let arrow_comment = { diff --git a/tests/source/attrib.rs b/tests/source/attrib.rs index f92c9cd31e2..7f17bdad0ac 100644 --- a/tests/source/attrib.rs +++ b/tests/source/attrib.rs @@ -217,3 +217,18 @@ fn stmt_expr_attributes() { #[must_use] foo = false ; } + +// #3509 +fn issue3509() { + match MyEnum { + MyEnum::Option1 if cfg!(target_os = "windows") => + #[cfg(target_os = "windows")]{ + 1 + } + } + match MyEnum { + MyEnum::Option1 if cfg!(target_os = "windows") => + #[cfg(target_os = "windows")] + 1, + } +} diff --git a/tests/target/attrib.rs b/tests/target/attrib.rs index b5a6c3491de..edde124a6c0 100644 --- a/tests/target/attrib.rs +++ b/tests/target/attrib.rs @@ -252,3 +252,21 @@ fn stmt_expr_attributes() { #[must_use] foo = false; } + +// #3509 +fn issue3509() { + match MyEnum { + MyEnum::Option1 if cfg!(target_os = "windows") => + #[cfg(target_os = "windows")] + { + 1 + } + } + match MyEnum { + MyEnum::Option1 if cfg!(target_os = "windows") => + { + #[cfg(target_os = "windows")] + 1 + } + } +}