From 0d4fb2403cf30e452f39f78d5a463738a35a52bb Mon Sep 17 00:00:00 2001 From: topecongiro Date: Sun, 14 Apr 2019 20:12:58 +0900 Subject: [PATCH 1/3] Add a test for #3509 --- tests/source/attrib.rs | 15 +++++++++++++++ tests/target/attrib.rs | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/tests/source/attrib.rs b/tests/source/attrib.rs index f92c9cd31e23..7f17bdad0ac2 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 b5a6c3491de1..edde124a6c08 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 + } + } +} From 3d80678e248ec880b5ee363f123b298189c7724b Mon Sep 17 00:00:00 2001 From: topecongiro Date: Sun, 14 Apr 2019 20:13:07 +0900 Subject: [PATCH 2/3] Do not include body's attributes in `arrow_span` --- src/matches.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/matches.rs b/src/matches.rs index c3102f121234..84fe1bdafe80 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, From b57e0e22795a881b670defa205908964fb0a8040 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Sun, 14 Apr 2019 20:13:54 +0900 Subject: [PATCH 3/3] Disallow putting a body with attributes on the same line --- src/matches.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/matches.rs b/src/matches.rs index 84fe1bdafe80..c09949cf2e86 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -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 = {