Format Struct { .. }
on one line even with {:#?}
.
This commit is contained in:
parent
c18c0ad2bc
commit
82dc73b1ae
2 changed files with 10 additions and 24 deletions
|
@ -188,28 +188,19 @@ impl<'a, 'b: 'a> DebugStruct<'a, 'b> {
|
||||||
#[stable(feature = "debug_non_exhaustive", since = "1.53.0")]
|
#[stable(feature = "debug_non_exhaustive", since = "1.53.0")]
|
||||||
pub fn finish_non_exhaustive(&mut self) -> fmt::Result {
|
pub fn finish_non_exhaustive(&mut self) -> fmt::Result {
|
||||||
self.result = self.result.and_then(|_| {
|
self.result = self.result.and_then(|_| {
|
||||||
// Draw non-exhaustive dots (`..`), and open brace if necessary (no fields).
|
if self.has_fields {
|
||||||
if self.is_pretty() {
|
if self.is_pretty() {
|
||||||
if !self.has_fields {
|
let mut slot = None;
|
||||||
self.fmt.write_str(" {\n")?;
|
let mut state = Default::default();
|
||||||
}
|
let mut writer = PadAdapter::wrap(&mut self.fmt, &mut slot, &mut state);
|
||||||
let mut slot = None;
|
writer.write_str("..\n")?;
|
||||||
let mut state = Default::default();
|
self.fmt.write_str("}")
|
||||||
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(", ..")?;
|
|
||||||
} else {
|
} else {
|
||||||
self.fmt.write_str(" { ..")?;
|
self.fmt.write_str(", .. }")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if self.is_pretty() {
|
|
||||||
self.fmt.write_str("}")?
|
|
||||||
} else {
|
} else {
|
||||||
self.fmt.write_str(" }")?;
|
self.fmt.write_str(" { .. }")
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
});
|
});
|
||||||
self.result
|
self.result
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,12 +105,7 @@ mod debug_struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!("Foo { .. }", format!("{:?}", Foo));
|
assert_eq!("Foo { .. }", format!("{:?}", Foo));
|
||||||
assert_eq!(
|
assert_eq!("Foo { .. }", format!("{:#?}", Foo));
|
||||||
"Foo {
|
|
||||||
..
|
|
||||||
}",
|
|
||||||
format!("{:#?}", Foo)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue