From bf775785e0ed7bcc76f81e9f7ba3c08363c571a6 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Wed, 15 Nov 2017 10:44:51 +0900 Subject: [PATCH 1/3] Add a test for #2151 --- tests/source/match.rs | 9 +++++++++ tests/target/match.rs | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/tests/source/match.rs b/tests/source/match.rs index ebae067b1543..23df0d3b6813 100644 --- a/tests/source/match.rs +++ b/tests/source/match.rs @@ -435,6 +435,15 @@ impl<'tcx> Const<'tcx> { } } +// #2151 +fn issue_2151() { + match either { + x => { + + }y => () + } +} + // #2152 fn issue_2152() { match m { diff --git a/tests/target/match.rs b/tests/target/match.rs index 34d23630df61..ea83effef811 100644 --- a/tests/target/match.rs +++ b/tests/target/match.rs @@ -476,6 +476,14 @@ impl<'tcx> Const<'tcx> { } } +// #2151 +fn issue_2151() { + match either { + x => {} + y => (), + } +} + // #2152 fn issue_2152() { match m { From 37b1779426f42d82c563a963f58f03172e88e5aa Mon Sep 17 00:00:00 2001 From: topecongiro Date: Wed, 15 Nov 2017 10:55:40 +0900 Subject: [PATCH 2/3] Look for a newline after match arm only when there is one --- src/lists.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lists.rs b/src/lists.rs index d7098d3a3974..a5d2334dcdab 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -602,7 +602,11 @@ where // Match arms may not have trailing comma. In any case, for match arms, // we will assume that the post comment belongs to the next arm if they // do not end with trailing comma. - 1 + if let Some(newline_index) = newline_index { + newline_index + 1 + } else { + 0 + } } } None => post_snippet From 1dc9b927af2718b4547ae193a02e6bb310516734 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Wed, 15 Nov 2017 10:56:26 +0900 Subject: [PATCH 3/3] Update tests --- tests/target/match.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/target/match.rs b/tests/target/match.rs index ea83effef811..3e04f4ca4be2 100644 --- a/tests/target/match.rs +++ b/tests/target/match.rs @@ -128,15 +128,13 @@ fn issue339() { h => { // comment above block } - i => {} - // comment below block + i => {} // comment below block j => { // comment inside block } j2 => { // comments inside... - } - // ... and after + } // ... and after // TODO uncomment when vertical whitespace is handled better // k => { //