diff --git a/src/missed_spans.rs b/src/missed_spans.rs index b83f07e05d7..99c1510da65 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -143,11 +143,12 @@ impl<'a> FmtVisitor<'a> { line_start = offset + subslice.len(); if let Some('/') = subslice.chars().skip(1).next() { + // Add a newline after line comments self.buffer.push_str("\n"); } else if line_start < snippet.len() { - let x = (&snippet[line_start..]).chars().next().unwrap() != '\n'; - - if x { + // For other comments add a newline if there isn't one at the end already + let c = snippet[line_start..].chars().next().unwrap(); + if c != '\n' && c != '\r' { self.buffer.push_str("\n"); } } diff --git a/tests/source/comment_crlf_newline.rs b/tests/source/comment_crlf_newline.rs new file mode 100644 index 00000000000..189a7053179 --- /dev/null +++ b/tests/source/comment_crlf_newline.rs @@ -0,0 +1,3 @@ +/* Block comments followed by CRLF newlines should not an extra newline at the end */ + +/* Something else */ diff --git a/tests/target/comment_crlf_newline.rs b/tests/target/comment_crlf_newline.rs new file mode 100644 index 00000000000..3b19b01a7eb --- /dev/null +++ b/tests/target/comment_crlf_newline.rs @@ -0,0 +1,3 @@ +// Block comments followed by CRLF newlines should not an extra newline at the end + +// Something else