Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 71289e1

Browse files
rchaser53topecongiro
authored andcommitted
fix 'extra comma inserted due to comment' (rust-lang#3677)
1 parent e55fc6b commit 71289e1

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/lists.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,11 @@ pub(crate) fn extract_post_comment(
612612
post_snippet[1..].trim_matches(white_space)
613613
} else if post_snippet.starts_with(separator) {
614614
post_snippet[separator.len()..].trim_matches(white_space)
615-
} else if post_snippet.ends_with(',') && !post_snippet.trim().starts_with("//") {
615+
}
616+
// not comment or over two lines
617+
else if post_snippet.ends_with(',')
618+
&& (!post_snippet.trim().starts_with("//") || post_snippet.trim().contains('\n'))
619+
{
616620
post_snippet[..(post_snippet.len() - 1)].trim_matches(white_space)
617621
} else {
618622
post_snippet

tests/source/issue-3675.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
println!("{}"
3+
// comment
4+
, 111);
5+
}

tests/target/issue-3675.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
println!(
3+
"{}", // comment
4+
111
5+
);
6+
}

0 commit comments

Comments
 (0)