Skip to content

Commit 0c05219

Browse files
committed
Auto merge of #26913 - sfackler:tuple-debug, r=alexcrichton
This does change the Debug output for 1-tuples to `(foo)` instead of `(foo,)` but I don't think it's that big of a deal. r? @alexcrichton
2 parents b8bb908 + b0ab164 commit 0c05219

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/libcore/fmt/builders.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ impl<'a, 'b: 'a> DebugTuple<'a, 'b> {
175175
fn is_pretty(&self) -> bool {
176176
self.fmt.flags() & (1 << (FlagV1::Alternate as usize)) != 0
177177
}
178+
179+
/// Returns the wrapped `Formatter`.
180+
#[unstable(feature = "debug_builder_formatter", reason = "recently added")]
181+
pub fn formatter(&mut self) -> &mut fmt::Formatter<'b> {
182+
&mut self.fmt
183+
}
178184
}
179185

180186
struct DebugInner<'a, 'b: 'a> {

src/libcore/fmt/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,20 +1488,19 @@ 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;
14931493
let mut n = 0;
14941494
$(
1495-
if n > 0 {
1496-
try!(write!(f, ", "));
1497-
}
1498-
try!(write!(f, "{:?}", *$name));
1495+
builder.field($name);
14991496
n += 1;
15001497
)*
1498+
15011499
if n == 1 {
1502-
try!(write!(f, ","));
1500+
try!(write!(builder.formatter(), ","));
15031501
}
1504-
write!(f, ")")
1502+
1503+
builder.finish()
15051504
}
15061505
}
15071506
peel! { $($name,)* }

0 commit comments

Comments
 (0)