diff options
| author | bors <bors@rust-lang.org> | 2015-07-11 23:41:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-07-11 23:41:07 +0000 |
| commit | 0c052199b92104ba6d64886ff779cf89c3c384d9 (patch) | |
| tree | 6afbd78244b5517e436057c506922ea2c367a08c | |
| parent | b8bb908d8829e7834748261a61605be2523fc878 (diff) | |
| parent | b0ab164b80f8d559cfc96e1d1d3819993672cced (diff) | |
| download | rust-0c052199b92104ba6d64886ff779cf89c3c384d9.tar.gz rust-0c052199b92104ba6d64886ff779cf89c3c384d9.zip | |
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
| -rw-r--r-- | src/libcore/fmt/builders.rs | 6 | ||||
| -rw-r--r-- | src/libcore/fmt/mod.rs | 13 |
2 files changed, 12 insertions, 7 deletions
diff --git a/src/libcore/fmt/builders.rs b/src/libcore/fmt/builders.rs index 32d6aa19c64..22f0215f0ad 100644 --- a/src/libcore/fmt/builders.rs +++ b/src/libcore/fmt/builders.rs @@ -175,6 +175,12 @@ impl<'a, 'b: 'a> DebugTuple<'a, 'b> { fn is_pretty(&self) -> bool { self.fmt.flags() & (1 << (FlagV1::Alternate as usize)) != 0 } + + /// Returns the wrapped `Formatter`. + #[unstable(feature = "debug_builder_formatter", reason = "recently added")] + pub fn formatter(&mut self) -> &mut fmt::Formatter<'b> { + &mut self.fmt + } } struct DebugInner<'a, 'b: 'a> { diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 47030bf0fb3..29a2f76ef29 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -1488,20 +1488,19 @@ 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)); + builder.field($name); n += 1; )* + if n == 1 { - try!(write!(f, ",")); + try!(write!(builder.formatter(), ",")); } - write!(f, ")") + + builder.finish() } } peel! { $($name,)* } |
