about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2021-04-21 13:50:56 +0200
committerMara Bos <m-ou.se@m-ou.se>2021-04-21 13:50:56 +0200
commit82dc73b1aef4a687466e00d87c5791b2a04d28f9 (patch)
tree7d73f8fc2bdb2d9737bfff946fddb332cfe53962
parentc18c0ad2bc5988ca7953459e5a35ece8e69e35e7 (diff)
downloadrust-82dc73b1aef4a687466e00d87c5791b2a04d28f9.tar.gz
rust-82dc73b1aef4a687466e00d87c5791b2a04d28f9.zip
Format `Struct { .. }` on one line even with `{:#?}`.
-rw-r--r--library/core/src/fmt/builders.rs27
-rw-r--r--library/core/tests/fmt/builders.rs7
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 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
     #[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 @@ mod debug_struct {
         }
 
         assert_eq!("Foo { .. }", format!("{:?}", Foo));
-        assert_eq!(
-            "Foo {
-    ..
-}",
-            format!("{:#?}", Foo)
-        );
+        assert_eq!("Foo { .. }", format!("{:#?}", Foo));
     }
 
     #[test]