-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Make fmt::DebugList and friends forward formatting parameters #46233
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @sfackler (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
For example, formatting slice of integers with `{:04?}` should zero-pad each integer.
793b55c
to
e0e7ac3
Compare
src/libcore/fmt/builders.rs
Outdated
writer.write_str("\n")?; | ||
writer.write_str(name)?; | ||
writer.write_str(": ")?; | ||
value.fmt(&mut writer.as_formatter()) |
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.
What's the difference between using this and value.fmt(writer.fmt)
here?
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.
That would break the indentation and newline insertion that PadAdapter
is there to do, which is particularly useful for deeply nested structures.
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 see! I thinking we could have written this without privileged access to formatter internals, but this way has less indirections and in debug struct it really benefits everyone, so I think it serves its purpose.
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 tried making this a method of Formatter
instead, but couldn’t borrow &mut writer
and &mut writer.fmt
at the same time.
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.
Alright, I found a way to make it work (in a new commit) but it’s a bit messy with up to three named lifetimes in the same item. I’m not sure that it’s better than before. What do you think?
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 think it looks quite neat. I'd pinpoint two places to place comments and it's good for me: 1. What's the slot argument?, 2. One sentence explaining the wrap_buf method. (The comment "We want to change this" is a sign that a prior brief comment is missing IMO)
Why would padding be applied to elements and not the list as a whole? |
It’s… better than nothing? I assume you mean space-padding. For what it’s worth, I mostly wanted this for zero-padding for example And padding is just an example, this forwards other formatting parameters like plus sign and precision too. |
Hmm, not sure how I feel about pushing this kind of thing down, but I don't think we have any precedent either way. Thoughts @rust-lang/libs? @rfcbot fcp merge |
Team member @sfackler has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
I share @sfackler's wariness here in that this implementation seems almost guaranteed for someone 6 months from now to open a bug saying "this is implementation is confusing and not obvious". It definitely isn't really respecting the various formatting flags in the same way types like That being said these are I do think we should clarify in documentation what's happening here. Either on |
Ping² @BurntSushi, @aturon, ticky boxes for you! |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
@bors: r=sfackler |
📌 Commit bf08789 has been approved by |
⌛ Testing commit bf08789 with merge a5f1195d10efd5379072c89e24f0b56939fb4644... |
💔 Test failed - status-travis |
@bors: retry
|
Make fmt::DebugList and friends forward formatting parameters For example, formatting slice of integers with `{:04?}` should zero-pad each integer. This also affects every use of `#[derive(Debug)]`.
☀️ Test successful - status-appveyor, status-travis |
For example, formatting slice of integers with
{:04?}
should zero-pad each integer.This also affects every use of
#[derive(Debug)]
.