From 25a0b917f3a1ac4ed2f2ec8588f1dbdf5ae0b5d0 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Fri, 20 Nov 2026 03:38:33 -0600 Subject: [PATCH] fmt: Implement `Debug` for `Formatter` This is a public type that doesn't currently have a debug implementation, but that would be helpful for peeking at format specifiers. Using `.options()` may be nicer for this usecase once it is stable, but it does not hurt to have an implementation anyway; thus, add one here. As this is a new trait implementation, it is inst-stable under a new `formatter_debug` feature. --- library/core/src/fmt/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 96dde7a11891b..202bc4ee2728c 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -2788,6 +2788,16 @@ impl Write for Formatter<'_> { } } +#[stable(feature = "formatter_debug", since = "CURRENT_RUSTC_VERSION")] +impl Debug for Formatter<'_> { + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + f.debug_struct("Formatter") + .field("options", &self.options) + .field_with("buf", |f| write!(f, "&mut dyn Write")) + .finish() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Display for Error { fn fmt(&self, f: &mut Formatter<'_>) -> Result {