Skip to content

Commit 82dc73b

Browse files
committed
Format Struct { .. } on one line even with {:#?}.
1 parent c18c0ad commit 82dc73b

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed

library/core/src/fmt/builders.rs

+9-18
Original file line numberDiff line numberDiff line change
@@ -188,28 +188,19 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
188188
#[stable(feature = "debug_non_exhaustive", since = "1.53.0")]
189189
pub fn finish_non_exhaustive(&mut self) -> fmt::Result {
190190
self.result = self.result.and_then(|_| {
191-
// Draw non-exhaustive dots (`..`), and open brace if necessary (no fields).
192-
if self.is_pretty() {
193-
if !self.has_fields {
194-
self.fmt.write_str(" {\n")?;
195-
}
196-
let mut slot = None;
197-
let mut state = Default::default();
198-
let mut writer = PadAdapter::wrap(&mut self.fmt, &mut slot, &mut state);
199-
writer.write_str("..\n")?;
200-
} else {
201-
if self.has_fields {
202-
self.fmt.write_str(", ..")?;
191+
if self.has_fields {
192+
if self.is_pretty() {
193+
let mut slot = None;
194+
let mut state = Default::default();
195+
let mut writer = PadAdapter::wrap(&mut self.fmt, &mut slot, &mut state);
196+
writer.write_str("..\n")?;
197+
self.fmt.write_str("}")
203198
} else {
204-
self.fmt.write_str(" { ..")?;
199+
self.fmt.write_str(", .. }")
205200
}
206-
}
207-
if self.is_pretty() {
208-
self.fmt.write_str("}")?
209201
} else {
210-
self.fmt.write_str(" }")?;
202+
self.fmt.write_str(" { .. }")
211203
}
212-
Ok(())
213204
});
214205
self.result
215206
}

library/core/tests/fmt/builders.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,7 @@ mod debug_struct {
105105
}
106106

107107
assert_eq!("Foo { .. }", format!("{:?}", Foo));
108-
assert_eq!(
109-
"Foo {
110-
..
111-
}",
112-
format!("{:#?}", Foo)
113-
);
108+
assert_eq!("Foo { .. }", format!("{:#?}", Foo));
114109
}
115110

116111
#[test]

0 commit comments

Comments
 (0)