Skip to content

Commit b02f1f4

Browse files
committed
Don't pretty-print trailing whitespace for blank lines inside block comments
1 parent 84fb821 commit b02f1f4

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/comp/syntax/print/pprust.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,12 @@ fn print_comment(s: &ps, cmnt: lexer::cmnt) {
15371537
}
15381538
lexer::isolated. {
15391539
pprust::hardbreak_if_not_bol(s);
1540-
for line: str in cmnt.lines { word(s.s, line); hardbreak(s.s); }
1540+
for line: str in cmnt.lines {
1541+
// Don't print empty lines because they will end up as trailing
1542+
// whitespace
1543+
if str::is_not_empty(line) { word(s.s, line); }
1544+
hardbreak(s.s);
1545+
}
15411546
}
15421547
lexer::trailing. {
15431548
word(s.s, " ");
@@ -1546,7 +1551,10 @@ fn print_comment(s: &ps, cmnt: lexer::cmnt) {
15461551
hardbreak(s.s);
15471552
} else {
15481553
ibox(s, 0u);
1549-
for line: str in cmnt.lines { word(s.s, line); hardbreak(s.s); }
1554+
for line: str in cmnt.lines {
1555+
if str::is_not_empty(line) { word(s.s, line); }
1556+
hardbreak(s.s);
1557+
}
15501558
end(s);
15511559
}
15521560
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// pp-exact
2+
fn f() {
3+
/*
4+
The next line should not be indented.
5+
6+
That one. It shouldn't have been indented.
7+
*/
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// pp-exact
2+
fn f() {
3+
} /*
4+
The next line should not be indented.
5+
6+
That one. It shouldn't have been indented.
7+
*/

0 commit comments

Comments
 (0)