Skip to content
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

Merged
merged 2 commits into from
Dec 20, 2017

Conversation

SimonSapin
Copy link
Contributor

@SimonSapin SimonSapin commented Nov 24, 2017

For example, formatting slice of integers with {:04?} should zero-pad each integer.

This also affects every use of #[derive(Debug)].

@rust-highfive
Copy link
Collaborator

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.
@kennytm kennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Nov 24, 2017
writer.write_str("\n")?;
writer.write_str(name)?;
writer.write_str(": ")?;
value.fmt(&mut writer.as_formatter())
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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?

Copy link
Member

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)

@sfackler
Copy link
Member

Why would padding be applied to elements and not the list as a whole?

@SimonSapin
Copy link
Contributor Author

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 u32’s to 8 hexadecimal digits with rust-lang/rfcs#2226

And padding is just an example, this forwards other formatting parameters like plus sign and precision too.

@sfackler
Copy link
Member

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

@rfcbot
Copy link

rfcbot commented Nov 28, 2017

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.

@rfcbot rfcbot added the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Nov 28, 2017
@alexcrichton
Copy link
Member

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 str do (in that it's for the whole output not for each element).

That being said these are Debug (emphasis on debug) impls and are in general a little looser around requirements than other implementations. I could also imagine how these are certainly convenient when you want this behavior (which seems like you'd want this behavior more often than "do the flags for the whole output" behavior).

I do think we should clarify in documentation what's happening here. Either on std::fmt documentation or on the debug builder methods themselves.

@kennytm kennytm added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 6, 2017
@kennytm
Copy link
Member

kennytm commented Dec 6, 2017

Ping @BurntSushi, @aturon, ticky boxes for you!

@kennytm
Copy link
Member

kennytm commented Dec 13, 2017

Ping² @BurntSushi, @aturon, ticky boxes for you!

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Dec 19, 2017
@rfcbot
Copy link

rfcbot commented Dec 19, 2017

🔔 This is now entering its final comment period, as per the review above. 🔔

@alexcrichton
Copy link
Member

@bors: r=sfackler

@bors
Copy link
Contributor

bors commented Dec 19, 2017

📌 Commit bf08789 has been approved by sfackler

@bors
Copy link
Contributor

bors commented Dec 20, 2017

⌛ Testing commit bf08789 with merge a5f1195d10efd5379072c89e24f0b56939fb4644...

@bors
Copy link
Contributor

bors commented Dec 20, 2017

💔 Test failed - status-travis

@alexcrichton
Copy link
Member

@bors: retry

  • wedged download?

@bors
Copy link
Contributor

bors commented Dec 20, 2017

⌛ Testing commit bf08789 with merge 6dbf0ba...

bors added a commit that referenced this pull request Dec 20, 2017
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)]`.
@bors
Copy link
Contributor

bors commented Dec 20, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: sfackler
Pushing 6dbf0ba to master...

@bors bors merged commit bf08789 into rust-lang:master Dec 20, 2017
@SimonSapin SimonSapin deleted the fmt-debuglist-flags branch February 16, 2018 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants