diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 9d3e9abf55779..71dd72f06301d 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -189,7 +189,7 @@ pub trait Write { /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn write_fmt(mut self: &mut Self, args: Arguments<'_>) -> Result { - write(&mut self, args) + if let Some(s) = args.as_str() { self.write_str(s) } else { write(&mut self, args) } } } diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 96addbd1a0558..0b095c3218b9d 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -1649,6 +1649,10 @@ pub trait Write { /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> Result<()> { + if let Some(s) = fmt.as_str() { + return self.write_all(s.as_bytes()); + } + // Create a shim which translates a Write to a fmt::Write and saves // off I/O errors. instead of discarding them struct Adapter<'a, T: ?Sized + 'a> {