diff options
| author | Seiichi Uchida <seuchida@gmail.com> | 2019-04-17 11:39:44 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-17 11:39:44 -0700 |
| commit | 760ec07978b75746f9c8de2502f2882239ed9285 (patch) | |
| tree | bd4b659d970c1b5787260f5aac56cd6d29f28d98 | |
| parent | 3dc625c661924d47fcb040b27f56ab7a9a206c60 (diff) | |
| parent | b57e0e22795a881b670defa205908964fb0a8040 (diff) | |
Merge pull request #3510 from topecongiro/issue3509
Fix duplication of attributes on a match arm's body
| -rw-r--r-- | src/matches.rs | 5 | ||||
| -rw-r--r-- | tests/source/attrib.rs | 15 | ||||
| -rw-r--r-- | tests/target/attrib.rs | 18 |
3 files changed, 36 insertions, 2 deletions
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 + } + } +} |
