From b02f1f46e550e8f87df6c3ec7f9721b1f4edc958 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 18 Aug 2011 19:19:38 -0700 Subject: [PATCH] Don't pretty-print trailing whitespace for blank lines inside block comments --- src/comp/syntax/print/pprust.rs | 12 ++++++++++-- src/test/pretty/block-comment-trailing-whitespace.rs | 8 ++++++++ .../pretty/block-comment-trailing-whitespace2.rs | 7 +++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/test/pretty/block-comment-trailing-whitespace.rs create mode 100644 src/test/pretty/block-comment-trailing-whitespace2.rs diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 59531683074..a90088f2142 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -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 index 00000000000..80611467c4e --- /dev/null +++ b/src/test/pretty/block-comment-trailing-whitespace.rs @@ -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 index 00000000000..e3f6f891dcb --- /dev/null +++ b/src/test/pretty/block-comment-trailing-whitespace2.rs @@ -0,0 +1,7 @@ +// pp-exact +fn f() { +} /* + The next line should not be indented. + + That one. It shouldn't have been indented. + */