From 82dc73b1aef4a687466e00d87c5791b2a04d28f9 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 21 Apr 2021 13:50:56 +0200 Subject: [PATCH] Format `Struct { .. }` on one line even with `{:#?}`. --- library/core/src/fmt/builders.rs | 27 +++++++++------------------ library/core/tests/fmt/builders.rs | 7 +------ 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/library/core/src/fmt/builders.rs b/library/core/src/fmt/builders.rs index 475ebcf07d5..b660788c051 100644 --- a/library/core/src/fmt/builders.rs +++ b/library/core/src/fmt/builders.rs @@ -188,28 +188,19 @@ pub fn field(&mut self, name: &str, value: &dyn fmt::Debug) -> &mut Self { #[stable(feature = "debug_non_exhaustive", since = "1.53.0")] pub fn finish_non_exhaustive(&mut self) -> fmt::Result { self.result = self.result.and_then(|_| { - // Draw non-exhaustive dots (`..`), and open brace if necessary (no fields). - if self.is_pretty() { - if !self.has_fields { - self.fmt.write_str(" {\n")?; - } - let mut slot = None; - let mut state = Default::default(); - let mut writer = PadAdapter::wrap(&mut self.fmt, &mut slot, &mut state); - writer.write_str("..\n")?; - } else { - if self.has_fields { - self.fmt.write_str(", ..")?; + if self.has_fields { + if self.is_pretty() { + let mut slot = None; + let mut state = Default::default(); + let mut writer = PadAdapter::wrap(&mut self.fmt, &mut slot, &mut state); + writer.write_str("..\n")?; + self.fmt.write_str("}") } else { - self.fmt.write_str(" { ..")?; + self.fmt.write_str(", .. }") } - } - if self.is_pretty() { - self.fmt.write_str("}")? } else { - self.fmt.write_str(" }")?; + self.fmt.write_str(" { .. }") } - Ok(()) }); self.result } diff --git a/library/core/tests/fmt/builders.rs b/library/core/tests/fmt/builders.rs index 129c121e8ce..7580010a28b 100644 --- a/library/core/tests/fmt/builders.rs +++ b/library/core/tests/fmt/builders.rs @@ -105,12 +105,7 @@ fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { } assert_eq!("Foo { .. }", format!("{:?}", Foo)); - assert_eq!( - "Foo { - .. -}", - format!("{:#?}", Foo) - ); + assert_eq!("Foo { .. }", format!("{:#?}", Foo)); } #[test]