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
This commit is contained in:
commit
0c052199b9
2 changed files with 12 additions and 7 deletions
|
|
@ -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> {
|
||||
|
|
|
|||
|
|
@ -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,)* }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue