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 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..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 => { // @@ -476,6 +474,14 @@ impl<'tcx> Const<'tcx> { } } +// #2151 +fn issue_2151() { + match either { + x => {} + y => (), + } +} + // #2152 fn issue_2152() { match m {