Skip to content

Change tuple Debug impls to use builders#26913

Merged
bors merged 2 commits into
rust-lang:masterfrom
sfackler:tuple-debug
Jul 12, 2015
Merged

Change tuple Debug impls to use builders#26913
bors merged 2 commits into
rust-lang:masterfrom
sfackler:tuple-debug

Conversation

@sfackler

@sfackler sfackler commented Jul 9, 2015

Copy link
Copy Markdown
Member

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

@bluss

bluss commented Jul 9, 2015

Copy link
Copy Markdown
Contributor

Since it's using a macro, we could special case the unary tuple, so that we get the comma anyway? (1) is consistent with tuple structs, but I think it's a bit weird.

@alexcrichton

Copy link
Copy Markdown
Member

Yeah I think I'd prefer to keep the trailing comma on 1-tuples, but other than that r=me

@nagisa

nagisa commented Jul 10, 2015

Copy link
Copy Markdown
Member

Would be nice to keep Debug output as close to something that compiles. let x: (i32,) = (0); // note the missing comma does not.

@sfackler

Copy link
Copy Markdown
Member Author

Updated

@alexcrichton

Copy link
Copy Markdown
Member

In the interest of not having lingering unstable methods, could this do what @bluss mentioned and special case the 1-tuple case?

@sfackler

Copy link
Copy Markdown
Member Author

The machinery involved to properly handle the pretty case is involved enough (e.g. see fmt::builders::PadAdapter) that this is the lowest impact implementation I can see.

@bluss

bluss commented Jul 11, 2015

Copy link
Copy Markdown
Contributor

Yes on a closer look it's not easy, I trust what you think is best sfackler

@alexcrichton

Copy link
Copy Markdown
Member

Wouldn't it be something along the lines of:

fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
    if f.alternate_flag_enabled() {
        write!(f, "({:#?},)", self.0)
    } else {
        write!(f, "({:?},)", self.0)
    }
}

@sfackler

Copy link
Copy Markdown
Member Author

That'd generate

(Foo {
    bar: hi
},)

but the builder would generate

(
    Foo {
        bar: hi
    },
)

@alexcrichton

Copy link
Copy Markdown
Member

Hm ok, seems fine then.

@bors: r+ b0ab164

@bors

bors commented Jul 11, 2015

Copy link
Copy Markdown
Collaborator

⌛ Testing commit b0ab164 with merge 0c05219...

bors added a commit that referenced this pull request Jul 11, 2015
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
@bors

bors commented Jul 12, 2015

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants