Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

liigo
Copy link
Contributor

@liigo liigo commented Jul 8, 2015

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
Contributor

r? @aturon

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

@alexcrichton
Copy link
Member

r? @sfackler

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

sfackler commented Jul 8, 2015

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
Copy link
Contributor Author

liigo commented Jul 9, 2015

@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
Copy link
Member

sfackler commented Jul 9, 2015

The tuple behavior is a bug, not a feature.

@liigo
Copy link
Contributor Author

liigo commented Jul 10, 2015 via email

@liigo
Copy link
Contributor Author

liigo commented Jul 10, 2015

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

@bors
Copy link
Collaborator

bors commented Jul 12, 2015

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

@alexcrichton
Copy link
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