about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2023-09-06 19:31:48 +0200
committerLukas Wirth <lukastw97@gmail.com>2023-09-06 19:31:48 +0200
commit96f19231d3d241c41540570f6caee29666aa9384 (patch)
tree86f6821e9fd24f084244ed8be914687e4ef0e558
parent5046889f431e4eb94a1add6a23f023ae5e461a16 (diff)
downloadrust-96f19231d3d241c41540570f6caee29666aa9384.tar.gz
rust-96f19231d3d241c41540570f6caee29666aa9384.zip
Fix hir pretty printing emitting trailing whitespace
-rw-r--r--crates/hir-def/src/body/pretty.rs11
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()
+            }
         }
     }