From 71289e1d230d19f223e45b0abe75ae976f567900 Mon Sep 17 00:00:00 2001 From: rChaser53 Date: Sun, 14 Jul 2019 22:16:47 +0900 Subject: [PATCH] fix 'extra comma inserted due to comment' (#3677) --- src/lists.rs | 6 +++++- tests/source/issue-3675.rs | 5 +++++ tests/target/issue-3675.rs | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/source/issue-3675.rs create mode 100644 tests/target/issue-3675.rs diff --git a/src/lists.rs b/src/lists.rs index 4c31f670d4d47..ac83d7082c888 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 0000000000000..f16efb2dcac15 --- /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 0000000000000..62d986e77341f --- /dev/null +++ b/tests/target/issue-3675.rs @@ -0,0 +1,6 @@ +fn main() { + println!( + "{}", // comment + 111 + ); +}