]> git.lizzy.rs Git - rust.git/commitdiff
Don't pretty-print trailing whitespace for blank lines inside block comments
authorBrian Anderson <banderson@mozilla.com>
Fri, 19 Aug 2011 02:19:38 +0000 (19:19 -0700)
committerBrian Anderson <banderson@mozilla.com>
Fri, 19 Aug 2011 02:22:10 +0000 (19:22 -0700)
src/comp/syntax/print/pprust.rs
src/test/pretty/block-comment-trailing-whitespace.rs [new file with mode: 0644]
src/test/pretty/block-comment-trailing-whitespace2.rs [new file with mode: 0644]

index 5953168307493c962191542efd401927d79b97e4..a90088f214263bcec77218893ff273fb9b85554b 100644 (file)
@@ -1537,7 +1537,12 @@ fn print_comment(s: &ps, cmnt: lexer::cmnt) {
       }
       lexer::isolated. {
         pprust::hardbreak_if_not_bol(s);
-        for line: str in cmnt.lines { word(s.s, line); hardbreak(s.s); }
+        for line: str in cmnt.lines {
+            // Don't print empty lines because they will end up as trailing
+            // whitespace
+            if str::is_not_empty(line) { word(s.s, line); }
+            hardbreak(s.s);
+        }
       }
       lexer::trailing. {
         word(s.s, " ");
@@ -1546,7 +1551,10 @@ fn print_comment(s: &ps, cmnt: lexer::cmnt) {
             hardbreak(s.s);
         } else {
             ibox(s, 0u);
-            for line: str in cmnt.lines { word(s.s, line); hardbreak(s.s); }
+            for line: str in cmnt.lines {
+                if str::is_not_empty(line) { word(s.s, line); }
+                hardbreak(s.s);
+            }
             end(s);
         }
       }
diff --git a/src/test/pretty/block-comment-trailing-whitespace.rs b/src/test/pretty/block-comment-trailing-whitespace.rs
new file mode 100644 (file)
index 0000000..8061146
--- /dev/null
@@ -0,0 +1,8 @@
+// pp-exact
+fn f() {
+    /*
+    The next line should not be indented.
+
+    That one. It shouldn't have been indented.
+    */
+}
diff --git a/src/test/pretty/block-comment-trailing-whitespace2.rs b/src/test/pretty/block-comment-trailing-whitespace2.rs
new file mode 100644 (file)
index 0000000..e3f6f89
--- /dev/null
@@ -0,0 +1,7 @@
+// pp-exact
+fn f() {
+} /*
+  The next line should not be indented.
+
+  That one. It shouldn't have been indented.
+  */