-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Debug improvements #640
Debug improvements #640
Conversation
Yeah, this would be great! |
[ | ||
"a", | ||
"b", | ||
"c" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe these (and similar things with multiple elements, each on its own line) should be printed with trailing commas? I suppose an exception would have to be made to the last paragraph of this section:
In all cases, pretty printed and non-pretty printed output should differ only in the addition of newlines, whitespace, and trailing commas (i.e., commas that are directly followed by a closing delimiter on the next line, ignoring whitespace).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be fine with a trailing comma, but I think we should be consistent between the normal and pretty printed outputs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the consistency is important, as I'd write the trailing comma in the pretty-printed style, but not in the compact one.
Do you mean we're going to rename Show to Debug? Because I don't think we should add another trait just for the |
Great proposal, 👍 |
@P1start I see, thanks. |
Thanks for writing this up! It seems like it'd help a lot with various debugging here and there.
cc @wycats, @seanmonstar, this seems similar to our work week discussions of Show/String/friends |
Using methods on |
It could return a struct implementing |
Ah yes sorry that's what I was thinking as well,
|
Yep, that seems pretty reasonable. |
@alexcrichton updated |
I very much approve of the idea, but am worried about some of the specifics. First of all, I think polymorphic types should be instantiated for clarity, i.e. Second, for good pretty printing, you want to new-line separate vs space separate to respect line length and consistency. I.E.
Is no good. I need to consult the exist literature, but I'm pretty sure what this means is that the data structure being printed should first be converted to a I was inclined to say the data structure should be built functionally rather than imperatively (like the calls to fmt), because the alternative is way more complex and potentially unsafe. But unless rustc can deforest that data structure in the ugly print case, perhaps its better to keep the imperative interface so that debugging without dynamic allocation works. Maybe guards can be used to ensure all brackets are closed, and even closed in the correct order (borrow close-guard to make sub expr). |
(I'm re-assigning to @alexcrichton as the shepherd, since he's been more involved in the discussion so far.) |
Seems good to me. |
Typo:
Also, in your example:
Won't this display as: |
No, it'll display as the second form. Why do you think it wouldn't? |
The reason it currently works is that "fmt::Arguments" implements Debug to return the raw formatted string. However, for consistency with other Debug implementations, it should either return a quoted string, which is what "&str" and "String" currently return, or struct initializer syntax as per this rfc. Basically, it's somewhat coincidental that it currently works, perhaps there should be another method: |
There seems to be pretty broad support for this at this time and it should help make debugging these forms of structures much easier to write. These APIs will all land as initially Thanks again for the RFC @sfackler! |
Should |
Seems like it should to me, asserts are only really for debugging so it would be great to have stuff pretty printed there . There's also lots of stuff in src/libcore/fmt/mod.rs that doesn't account for this yet. I for one would like to have the ability to change the indentation size since it's quite easy to overflow the terminal width when printing recursive data structures but I understand this may not be desirable since it goes against the style guidelines. |
keywords: pretty debug builders |
Rendered