DisplayFn trait for print fns on clean rustdoc items#148740
Closed
yotamofek wants to merge 1 commit intorust-lang:masterfrom
Closed
DisplayFn trait for print fns on clean rustdoc items#148740yotamofek wants to merge 1 commit intorust-lang:masterfrom
DisplayFn trait for print fns on clean rustdoc items#148740yotamofek wants to merge 1 commit intorust-lang:masterfrom
Conversation
Collaborator
|
The job Click to see the possible cause of the failure (guessed by this bot) |
Member
|
I'm personally not very convinced by this approach. ^^' We basically exchange a level of indent for a level of indirection. It's a neat trick though. |
Contributor
Author
|
I can't convince you of something I don't believe in myself 😬 |
Member
|
I mean, we could bring this up at next rustdoc meeting (which is tomorrow haha). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Not sure if I like this change or not, but it has some pros (and cons) so thought I'd put it up here for discussion.
In #148585 (comment), I lamented the fact that there was a lot of boilerplate around our
print_*fns, due to thefmt::from_fnopening a new block (and indenting everything by another tab).Using a macro to change the signature of a function is definitely not a good idea, so I attempted to do something similar with a trait and a blanket impl.
Basically, the
DisplayFntrait is implemented for fns that take a&mut fmt::Formatter, a "clean" item, and a rustdoc ctx, and adds adisplay_fnmethod on such functions that does the wholefmt::from_fnwrapping.Pros:
&mut Formattercan just pass it to the original function, while those that don't can use thedisplay_fntrait methodMajor con:
Fns are not the greatest DX. If you get a function signature wrong, the diagnostics are not going to be very helpful. And it's not really clear where thatdisplay_fnmethod is coming from (though I don't think it should matter much most of the time, since its functionality is pretty easy to infer from the context, IMHO)r? @GuillaumeGomez feel free to just close this if you don't like the idea, not married to it myself :)