diff --git a/src/formatting/lists.rs b/src/formatting/lists.rs index 6d9aa529f7c..447c40bcd03 100644 --- a/src/formatting/lists.rs +++ b/src/formatting/lists.rs @@ -569,7 +569,7 @@ where formatted_comment = rewrite_post_comment(&mut item_max_width)?; } - if !starts_with_newline(comment) { + if !starts_with_newline(comment) || !separate { if formatting.align_comments { let mut comment_alignment = post_comment_alignment( item_max_width, diff --git a/tests/source/issue-4757.rs b/tests/source/issue-4757.rs new file mode 100644 index 00000000000..c1e88f3fa97 --- /dev/null +++ b/tests/source/issue-4757.rs @@ -0,0 +1,30 @@ +fn main() { + match 1 { + _ => {}, + // hello! + } +} + +fn main() { + match 1 { + _ => {} + // hello! + } +} + +fn main() { + match 1 { + 1 => {}, + // hello + _ => {}, + // world! + } +} + +fn main() { + match 1 { + 1 => {} + // hello + _ => {} // world! + } +} diff --git a/tests/target/issue-4757.rs b/tests/target/issue-4757.rs new file mode 100644 index 00000000000..ffa225cfca2 --- /dev/null +++ b/tests/target/issue-4757.rs @@ -0,0 +1,27 @@ +fn main() { + match 1 { + _ => {} // hello! + } +} + +fn main() { + match 1 { + _ => {} // hello! + } +} + +fn main() { + match 1 { + 1 => {} + // hello + _ => {} // world! + } +} + +fn main() { + match 1 { + 1 => {} + // hello + _ => {} // world! + } +}