Skip to content

Commit 96f1923

Browse files
committed
Fix hir pretty printing emitting trailing whitespace
1 parent 5046889 commit 96f1923

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

crates/hir-def/src/body/pretty.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,14 @@ impl Printer<'_> {
140140
}
141141

142142
fn newline(&mut self) {
143-
match self.buf.chars().rev().find(|ch| *ch != ' ') {
144-
Some('\n') | None => {}
145-
_ => writeln!(self).unwrap(),
143+
match self.buf.chars().rev().find_position(|ch| *ch != ' ') {
144+
Some((_, '\n')) | None => {}
145+
Some((idx, _)) => {
146+
if idx != 0 {
147+
self.buf.drain(self.buf.len() - idx..);
148+
}
149+
writeln!(self).unwrap()
150+
}
146151
}
147152
}
148153

0 commit comments

Comments
 (0)