Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 0bcbd16

Browse files
committed
Change tuple Debug impls to use builders
1 parent afe25a2 commit 0bcbd16

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

src/libcore/fmt/mod.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,20 +1488,10 @@ macro_rules! tuple {
14881488
impl<$($name:Debug),*> Debug for ($($name,)*) {
14891489
#[allow(non_snake_case, unused_assignments)]
14901490
fn fmt(&self, f: &mut Formatter) -> Result {
1491-
try!(write!(f, "("));
1491+
let mut builder = f.debug_tuple("");
14921492
let ($(ref $name,)*) = *self;
1493-
let mut n = 0;
1494-
$(
1495-
if n > 0 {
1496-
try!(write!(f, ", "));
1497-
}
1498-
try!(write!(f, "{:?}", *$name));
1499-
n += 1;
1500-
)*
1501-
if n == 1 {
1502-
try!(write!(f, ","));
1503-
}
1504-
write!(f, ")")
1493+
$(builder.field($name);)*
1494+
builder.finish()
15051495
}
15061496
}
15071497
peel! { $($name,)* }

src/libcoretest/tuple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn test_tuple_cmp() {
6060
#[test]
6161
fn test_show() {
6262
let s = format!("{:?}", (1,));
63-
assert_eq!(s, "(1,)");
63+
assert_eq!(s, "(1)");
6464
let s = format!("{:?}", (1, true));
6565
assert_eq!(s, "(1, true)");
6666
let s = format!("{:?}", (1, "hi", true));

0 commit comments

Comments
 (0)