Uh oh!
There was an error while loading. Please reload this page.
Debug improvements - #640
Conversation
blaenk
commented
Jan 21, 2015
Yeah, this would be great! |
There was a problem hiding this comment.
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.
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.
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.
kennytm
commented
Jan 21, 2015
Do you mean we're going to rename Show to Debug? Because I don't think we should add another trait just for the |
ftxqxd
commented
Jan 21, 2015
aldanor
commented
Jan 21, 2015
Great proposal, 👍 |
kennytm
commented
Jan 21, 2015
@P1start I see, thanks. |
alexcrichton
commented
Jan 21, 2015
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 |
sfackler
commented
Jan 21, 2015
Using methods on |
sfackler
commented
Jan 21, 2015
It could return a struct implementing |
alexcrichton
commented
Jan 21, 2015
Ah yes sorry that's what I was thinking as well, |
sfackler
commented
Jan 21, 2015
Yep, that seems pretty reasonable. |
sfackler
commented
Jan 22, 2015
@alexcrichton updated |
Ericson2314
commented
Jan 25, 2015
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). |
aturon
commented
Feb 16, 2015
(I'm re-assigning to @alexcrichton as the shepherd, since he's been more involved in the discussion so far.) |
nikomatsakis
commented
Mar 4, 2015
Seems good to me. |
Diggsey
commented
Mar 4, 2015
Typo:
Also, in your example:
Won't this display as: |
sfackler
commented
Mar 4, 2015
No, it'll display as the second form. Why do you think it wouldn't? |
Diggsey
commented
Mar 4, 2015
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: |
alexcrichton
commented
Mar 5, 2015
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! |
SimonSapin
commented
Apr 2, 2015
Should |
nwoeanhinnogaehr
commented
Apr 4, 2015
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. |
liigo
commented
Jul 8, 2015
keywords: pretty debug builders |
Rendered