Change tuple Debug impls to use builders

This commit is contained in:
Steven Fackler 2015-07-08 23:38:42 -07:00
parent afe25a2d6a
commit 0bcbd16931
2 changed files with 4 additions and 14 deletions

View File

@ -1488,20 +1488,10 @@ macro_rules! tuple {
impl<$($name:Debug),*> Debug for ($($name,)*) {
#[allow(non_snake_case, unused_assignments)]
fn fmt(&self, f: &mut Formatter) -> Result {
try!(write!(f, "("));
let mut builder = f.debug_tuple("");
let ($(ref $name,)*) = *self;
let mut n = 0;
$(
if n > 0 {
try!(write!(f, ", "));
}
try!(write!(f, "{:?}", *$name));
n += 1;
)*
if n == 1 {
try!(write!(f, ","));
}
write!(f, ")")
$(builder.field($name);)*
builder.finish()
}
}
peel! { $($name,)* }

View File

@ -60,7 +60,7 @@ fn test_tuple_cmp() {
#[test]
fn test_show() {
let s = format!("{:?}", (1,));
assert_eq!(s, "(1,)");
assert_eq!(s, "(1)");
let s = format!("{:?}", (1, true));
assert_eq!(s, "(1, true)");
let s = format!("{:?}", (1, "hi", true));