]> git.lizzy.rs Git - rust.git/commitdiff
Stop extra newlines from being added after block comments (#1185)
authorEdward Yang <edward.yang6771@gmail.com>
Mon, 24 Oct 2016 19:45:15 +0000 (14:45 -0500)
committerNick Cameron <nrc@ncameron.org>
Mon, 24 Oct 2016 19:45:15 +0000 (08:45 +1300)
src/missed_spans.rs
tests/source/issue-1177.rs [new file with mode: 0644]
tests/target/issue-1177.rs [new file with mode: 0644]

index 98d87ba4963c61d7794ec07349927c9882a79a5a..3372c05eb06111830fe6c87f4f0d827800433c6a 100644 (file)
@@ -144,8 +144,13 @@ fn replace_chars(string: &str) -> String {
                     line_start = offset + subslice.len();
 
                     if let Some('/') = subslice.chars().skip(1).next() {
-                        // Add a newline after line comments
-                        self.buffer.push_str("\n");
+                        // check that there are no contained block comments
+                        if !subslice.split('\n')
+                            .map(|s| s.trim_left())
+                            .any(|s| s.len() > 2 && &s[0..2] == "/*") {
+                            // Add a newline after line comments
+                            self.buffer.push_str("\n");
+                        }
                     } else if line_start <= snippet.len() {
                         // For other comments add a newline if there isn't one at the end already
                         match snippet[line_start..].chars().next() {
diff --git a/tests/source/issue-1177.rs b/tests/source/issue-1177.rs
new file mode 100644 (file)
index 0000000..053c732
--- /dev/null
@@ -0,0 +1,6 @@
+fn main() {
+    // Line Comment
+    /* Block Comment */
+
+    let d = 5;
+}
diff --git a/tests/target/issue-1177.rs b/tests/target/issue-1177.rs
new file mode 100644 (file)
index 0000000..377540e
--- /dev/null
@@ -0,0 +1,6 @@
+fn main() {
+    // Line Comment
+    // Block Comment
+
+    let d = 5;
+}