Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions src/libcore/fmt/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,7 @@ impl<'a, 'b: 'a> DebugTuple<'a, 'b> {
("(", "")
};

if self.is_pretty() {
let mut writer = PadAdapter::new(self.fmt);
fmt::write(&mut writer, format_args!("{}\n{:#?}", prefix, value))
} else {
write!(self.fmt, "{}{}{:?}", prefix, space, value)
}
write!(self.fmt, "{}{}{:?}", prefix, space, value)
});

self.has_fields = true;
Expand All @@ -162,19 +157,11 @@ impl<'a, 'b: 'a> DebugTuple<'a, 'b> {
pub fn finish(&mut self) -> fmt::Result {
if self.has_fields {
self.result = self.result.and_then(|_| {
if self.is_pretty() {
self.fmt.write_str("\n)")
} else {
self.fmt.write_str(")")
}
self.fmt.write_str(")")
});
}
self.result
}

fn is_pretty(&self) -> bool {
self.fmt.flags() & (1 << (FlagV1::Alternate as usize)) != 0
}
}

struct DebugInner<'a, 'b: 'a> {
Expand Down
42 changes: 23 additions & 19 deletions src/libcoretest/fmt/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ mod debug_tuple {

assert_eq!("Foo", format!("{:?}", Foo));
assert_eq!("Foo", format!("{:#?}", Foo));

assert_eq!("None", format!("{:?}", None::<Foo>));
assert_eq!("None", format!("{:#?}", None::<Foo>));
}

#[test]
Expand All @@ -135,11 +138,13 @@ mod debug_tuple {
}

assert_eq!("Foo(true)", format!("{:?}", Foo));
assert_eq!(
"Foo(
true
)",
format!("{:#?}", Foo));
assert_eq!("Foo(true)", format!("{:#?}", Foo));

assert_eq!("Some(1)", format!("{:?}", Some(1)));
assert_eq!("Some(1)", format!("{:#?}", Some(1)));

assert_eq!("(true,)", format!("{:?}", (true,)));
assert_eq!("(true,)", format!("{:#?}", (true,)));
}

#[test]
Expand All @@ -156,12 +161,10 @@ mod debug_tuple {
}

assert_eq!("Foo(true, 10/20)", format!("{:?}", Foo));
assert_eq!(
"Foo(
true,
10/20
)",
format!("{:#?}", Foo));
assert_eq!("Foo(true, 10/20)", format!("{:#?}", Foo));

assert_eq!("(true, 123)", format!("{:?}", (true, 123)));
assert_eq!("(true, 123)", format!("{:#?}", (true, 123)));
}

#[test]
Expand Down Expand Up @@ -190,15 +193,16 @@ mod debug_tuple {

assert_eq!("Bar(Foo(true, 10/20), \"world\")",
format!("{:?}", Bar));
assert_eq!(
"Bar(
Foo(
true,
10/20
),
\"world\"
)",
assert_eq!("Bar(Foo(true, 10/20), \"world\")",
format!("{:#?}", Bar));

#[derive(Debug)]
struct Baz {
value: i32
}

assert_eq!("(true, Baz { value: 1 })", format!("{:?}", (true, Baz { value: 1 })));
assert_eq!("(true, Baz { value: 1 })", format!("{:#?}", (true, Baz { value: 1 })));
}
}

Expand Down