diff --git a/src/lists.rs b/src/lists.rs index 4c31f670d4d..ac83d7082c8 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -612,7 +612,11 @@ pub(crate) fn extract_post_comment( post_snippet[1..].trim_matches(white_space) } else if post_snippet.starts_with(separator) { post_snippet[separator.len()..].trim_matches(white_space) - } else if post_snippet.ends_with(',') && !post_snippet.trim().starts_with("//") { + } + // not comment or over two lines + else if post_snippet.ends_with(',') + && (!post_snippet.trim().starts_with("//") || post_snippet.trim().contains('\n')) + { post_snippet[..(post_snippet.len() - 1)].trim_matches(white_space) } else { post_snippet diff --git a/tests/source/issue-3675.rs b/tests/source/issue-3675.rs new file mode 100644 index 00000000000..f16efb2dcac --- /dev/null +++ b/tests/source/issue-3675.rs @@ -0,0 +1,5 @@ + fn main() { + println!("{}" + // comment + , 111); + } \ No newline at end of file diff --git a/tests/target/issue-3675.rs b/tests/target/issue-3675.rs new file mode 100644 index 00000000000..62d986e7734 --- /dev/null +++ b/tests/target/issue-3675.rs @@ -0,0 +1,6 @@ +fn main() { + println!( + "{}", // comment + 111 + ); +}