Add trailing , for 1-tuples

This commit is contained in:
Steven Fackler 2015-07-10 11:03:52 -08:00
parent 0bcbd16931
commit b0ab164b80
3 changed files with 17 additions and 2 deletions

View File

@ -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> {

View File

@ -1490,7 +1490,16 @@ macro_rules! tuple {
fn fmt(&self, f: &mut Formatter) -> Result {
let mut builder = f.debug_tuple("");
let ($(ref $name,)*) = *self;
$(builder.field($name);)*
let mut n = 0;
$(
builder.field($name);
n += 1;
)*
if n == 1 {
try!(write!(builder.formatter(), ","));
}
builder.finish()
}
}

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));