about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMarkus Westerlind <marwes91@gmail.com>2015-11-20 23:31:05 +0100
committerMarkus Westerlind <marwes91@gmail.com>2015-11-20 23:31:05 +0100
commitad7dc420cdfe22c8295c36c4e3a66cc9cf1cbe2b (patch)
treec4e178b02211bd831c87fd416927a7c41b598af6 /src
parent3533f72c458d5772a47c9efda761edef396a9f0f (diff)
Avoid adding an extra newline after block comments
When block comments were rewritten to line comments they check if a new line needs to be added and adds one if needed. It only checked for '\n' however which would cause a newline to be added even if the comment was ended by "\r\n"
Diffstat (limited to 'src')
-rw-r--r--src/missed_spans.rs7
1 files changed, 4 insertions, 3 deletions
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");
                         }
                     }