Skip to content

core: fmt: debug builders pretty print tuple structs and enum variants in a single line#26874

Closed
liigo wants to merge 1 commit into
rust-lang:masterfrom
liigo:pretty-debug-tuple-without-newlines
Closed

core: fmt: debug builders pretty print tuple structs and enum variants in a single line#26874
liigo wants to merge 1 commit into
rust-lang:masterfrom
liigo:pretty-debug-tuple-without-newlines

Conversation

@liigo

@liigo liigo commented Jul 8, 2015

Copy link
Copy Markdown
Contributor

Before this PR, println!("{:#?}", Some(1)); pretty prints debug output as:

Some(
    1
)

(by adding newlines and indent)

But I don't think it's pretty print: it's weird, even not a preferred code style.

Some(1) itself (without newlines and indent) is pretty print, IMO.

This PR change the pretty print output, to print tuple structs and enum variants in a single line. (We already pretty print tuples in this way.)

Perhaps this is a [breaking-change]? And an RFC is required? I don't known.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @aturon

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton

Copy link
Copy Markdown
Member

r? @sfackler

@rust-highfive rust-highfive assigned sfackler and unassigned aturon Jul 8, 2015
@sfackler

sfackler commented Jul 8, 2015

Copy link
Copy Markdown
Member

The current behavior is intentional, as described in the RFC: rust-lang/rfcs#640. The pretty printing mode is designed for ease of readability, not matching rust style. Printing some things in one line and others in multiples does not nest well:

MyTupleStruct(MyStruct {
    a: 1,
    b: TupleStruct(MyOtherStruct {
        foo: bar
    }, 10, "hi", Thing {
        baz: buzz
    })
}, true, false, OtherStruct {
    thing: "hi"
})

It could potentially be nice to print single-variant tuples in one line if there are no line breaks in the output for the inner value, but I'm not sure how that would work.

@liigo

liigo commented Jul 9, 2015

Copy link
Copy Markdown
Contributor Author

@sfackler

The current behavior is intentional, as described in the RFC: rust-lang/rfcs#640

OK, maybe an RFC is required to propose changing this a bit?

The pretty printing mode is designed for ease of readability, not matching rust style.

But I do think that Some(1) is more readable than

Some(
    1
)

Printing some things in one line and others in multiples does not nest well

Tuples with nested struct, already pretty print in a single line, and this PR doesn't change that. http://is.gd/ZJKuVy

@sfackler

sfackler commented Jul 9, 2015

Copy link
Copy Markdown
Member

The tuple behavior is a bug, not a feature.

@liigo

liigo commented Jul 10, 2015 via email

Copy link
Copy Markdown
Contributor Author

@liigo

liigo commented Jul 10, 2015

Copy link
Copy Markdown
Contributor Author

I've written an RFC rust-lang/rfcs#1198

@bors

bors commented Jul 12, 2015

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #26913) made this pull request unmergeable. Please resolve the merge conflicts.

@alexcrichton

Copy link
Copy Markdown
Member

The associated RFC was closed, so I'm going to close this as well.

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.

6 participants