Skip to content

Commit

Permalink
fix 'extra comma inserted due to comment' (rust-lang#3677)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchaser53 authored and topecongiro committed Jul 14, 2019
1 parent e55fc6b commit 71289e1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/source/issue-3675.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
println!("{}"
// comment
, 111);
}
6 changes: 6 additions & 0 deletions tests/target/issue-3675.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
println!(
"{}", // comment
111
);
}

0 comments on commit 71289e1

Please sign in to comment.