Fix hir pretty printing emitting trailing whitespace

This commit is contained in:
Lukas Wirth 2023-09-06 19:31:48 +02:00
parent 5046889f43
commit 96f19231d3

View File

@ -140,9 +140,14 @@ impl Printer<'_> {
}
fn newline(&mut self) {
match self.buf.chars().rev().find(|ch| *ch != ' ') {
Some('\n') | None => {}
_ => writeln!(self).unwrap(),
match self.buf.chars().rev().find_position(|ch| *ch != ' ') {
Some((_, '\n')) | None => {}
Some((idx, _)) => {
if idx != 0 {
self.buf.drain(self.buf.len() - idx..);
}
writeln!(self).unwrap()
}
}
}