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

Treat empty doc comments that precede doc attributes as significant #5098

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ytmimi
Copy link
Contributor

@ytmimi ytmimi commented Nov 20, 2021

Fixes #5073

Normally we would want to remove any empty trailing doc comments
however, as highlighted by 5073 by removing these trailing comments
rustfmt is interfering with tools like rustdoc.

Checks have been added to allow rustfmt to keep empty trailing comments
when using wrap_comments = true if and only if the empty trailing
comments immideatly precede a doc attribute.

Fixes 5073

Normally we would want to remove any empty trailing doc comments
however, as highlighted by 5073 by removing these trailing comments
rustfmt is interfering with tools like rustdoc.

Checks have been added to allow rustfmt to keep empty trailing comments
when using ``wrap_comments = true`` if and only if the empty trailing
comments immideatly precede a doc attribute.
Copy link
Member

@calebcartwright calebcartwright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decent number of signatures and associated call sites needed to be updated but guess that"s not all that surprising given the pain of working with comments in general, so this works for me.

One minor thing, then content moving ahead to resolve the reported issue

@@ -0,0 +1,7 @@
// rustfmt-wrap_comments: false

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit but could you fix the typo in these file names? *_commet_* -> *_comment_*

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely not a nit at all! I appreciate you pointing this out and I"ll get to fixing it!

@ytmimi
Copy link
Contributor Author

ytmimi commented Feb 3, 2022

I agree there were a few signatures that needed to change. As you might tell from the code I was trying to find a way to dynamically determine if empty comments were significant. I"m definitely not married to this solution and open to suggestions you might have on how to fix this.

That being said, it"s been a while since I submitted this PR, and revisiting this now has got me wondering if a simpler approach would be to introduce a new unstable configuration option like retain_empty_doc_comments (name suggestions are also appreciated!). The CommentRewrite struct gets a reference to the config, so we could just let users decide whether or not rustfmt should remove empty doc comments or not.

@calebcartwright
Copy link
Member

That being said, it"s been a while since I submitted this PR, and revisiting this now has got me wondering if a simpler approach would be to introduce a new unstable configuration option like retain_empty_doc_comments (name suggestions are also appreciated!). The CommentRewrite struct gets a reference to the config, so we could just let users decide whether or not rustfmt should remove empty doc comments or not.

While that does sound like it"d make for a simpler implementation, do you think the categorical behavior associated with a config option will give users what they need in all contexts? My concern would be that the answer genuinely seems like "it depends" which is impossible to handle with a boolean-style config option, and I worry that an enum-style option would be challenging as well (what would the variants and their behaviors be?)

@ytmimi
Copy link
Contributor Author

ytmimi commented Feb 23, 2022

While that does sound like it"d make for a simpler implementation, do you think the categorical behavior associated with a config option will give users what they need in all contexts? My concern would be that the answer genuinely seems like "it depends" which is impossible to handle with a boolean-style config option, and I worry that an enum-style option would be challenging as well (what would the variants and their behaviors be?)

I think that"s a really good point. Let me think on this a bit and get back to you. To your point, it might be better to avoid going down the configuration option route, but part of me still thinks I can come up with a slightly cleaner way to handle this.

@ytmimi ytmimi added pr-merge-conflict This PR has merge conflicts that must be resolved p-low labels Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p-low pr-merge-conflict This PR has merge conflicts that must be resolved pr-waiting-on-author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

With wrap_comments = true, rustfmt removes significant empty doc lines
2 participants