about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-09-17 01:47:49 +0000
committerbors <bors@rust-lang.org>2023-09-17 01:47:49 +0000
commita09c1f85f1bc5be9a85e1395e7482caff91260cc (patch)
treec5e33e9cc15c309bfdf6ccafa365bdf4429855e5
parentd7229c479c5f330aac55f009892f82916057cf0a (diff)
parent814f4f6f526b302bda9a464130b97502e39cc490 (diff)
downloadrust-a09c1f85f1bc5be9a85e1395e7482caff91260cc.tar.gz
rust-a09c1f85f1bc5be9a85e1395e7482caff91260cc.zip
Auto merge of #115782 - a1phyr:improve_pad_adapter, r=dtolnay
Improve `PadAdapter::write_char`

Split from #108043
-rw-r--r--library/core/src/fmt/builders.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/library/core/src/fmt/builders.rs b/library/core/src/fmt/builders.rs
index d2c9f980042..9227248041e 100644
--- a/library/core/src/fmt/builders.rs
+++ b/library/core/src/fmt/builders.rs
@@ -40,6 +40,14 @@ impl fmt::Write for PadAdapter<'_, '_> {
 
         Ok(())
     }
+
+    fn write_char(&mut self, c: char) -> fmt::Result {
+        if self.state.on_newline {
+            self.buf.write_str("    ")?;
+        }
+        self.state.on_newline = c == '\n';
+        self.buf.write_char(c)
+    }
 }
 
 /// A struct to help with [`fmt::Debug`](Debug) implementations.