diff options
| author | Lukas Wirth <lukastw97@gmail.com> | 2023-09-06 19:31:48 +0200 |
|---|---|---|
| committer | Lukas Wirth <lukastw97@gmail.com> | 2023-09-06 19:31:48 +0200 |
| commit | 96f19231d3d241c41540570f6caee29666aa9384 (patch) | |
| tree | 86f6821e9fd24f084244ed8be914687e4ef0e558 | |
| parent | 5046889f431e4eb94a1add6a23f023ae5e461a16 (diff) | |
| download | rust-96f19231d3d241c41540570f6caee29666aa9384.tar.gz rust-96f19231d3d241c41540570f6caee29666aa9384.zip | |
Fix hir pretty printing emitting trailing whitespace
| -rw-r--r-- | crates/hir-def/src/body/pretty.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/crates/hir-def/src/body/pretty.rs b/crates/hir-def/src/body/pretty.rs index 31c2e9c1fb9..fad4d7a4da6 100644 --- a/crates/hir-def/src/body/pretty.rs +++ b/crates/hir-def/src/body/pretty.rs @@ -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() + } } } |
