summaryrefslogtreecommitdiffstats
path: root/library/core/src/fmt
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /library/core/src/fmt
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/core/src/fmt')
-rw-r--r--library/core/src/fmt/builders.rs8
-rw-r--r--library/core/src/fmt/mod.rs28
2 files changed, 32 insertions, 4 deletions
diff --git a/library/core/src/fmt/builders.rs b/library/core/src/fmt/builders.rs
index d2c9f9800..922724804 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.
diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs
index 9ce6093f1..fc91d1afc 100644
--- a/library/core/src/fmt/mod.rs
+++ b/library/core/src/fmt/mod.rs
@@ -112,9 +112,9 @@ pub trait Write {
///
/// # Errors
///
- /// This function will return an instance of [`Error`] on error.
+ /// This function will return an instance of [`std::fmt::Error`][Error] on error.
///
- /// The purpose of std::fmt::Error is to abort the formatting operation when the underlying
+ /// The purpose of that error is to abort the formatting operation when the underlying
/// destination encounters some error preventing it from accepting more text; it should
/// generally be propagated rather than handled, at least when implementing formatting traits.
///
@@ -188,8 +188,28 @@ pub trait Write {
/// assert_eq!(&buf, "world");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
- fn write_fmt(mut self: &mut Self, args: Arguments<'_>) -> Result {
- write(&mut self, args)
+ fn write_fmt(&mut self, args: Arguments<'_>) -> Result {
+ // We use a specialization for `Sized` types to avoid an indirection
+ // through `&mut self`
+ trait SpecWriteFmt {
+ fn spec_write_fmt(self, args: Arguments<'_>) -> Result;
+ }
+
+ impl<W: Write + ?Sized> SpecWriteFmt for &mut W {
+ #[inline]
+ default fn spec_write_fmt(mut self, args: Arguments<'_>) -> Result {
+ write(&mut self, args)
+ }
+ }
+
+ impl<W: Write> SpecWriteFmt for &mut W {
+ #[inline]
+ fn spec_write_fmt(self, args: Arguments<'_>) -> Result {
+ write(self, args)
+ }
+ }
+
+ self.spec_write_fmt(args)
}
}