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

Fix #5533: Prefer light_rewrite_comment if it is not a doccomment #5536

Merged
merged 4 commits into from
Sep 11, 2023

Conversation

pan93412
Copy link
Contributor

@pan93412 pan93412 commented Sep 6, 2022

This pull request adapts the plan 2 of @ytmimi's comment, and it won't touch any comment which is not a documentation comment now.

However, it did not fixed the root cause (which is partially indicated in Plan 1): block_comment is true if the length is too long…?. As it seems not related to #5533, it may be fixed in another PR.

image

@pan93412
Copy link
Contributor Author

pan93412 commented Sep 6, 2022

cc @ytmimi . Thanks!

@pan93412 pan93412 marked this pull request as draft September 6, 2022 16:37
@pan93412 pan93412 marked this pull request as ready for review September 6, 2022 16:45
src/comment.rs Outdated Show resolved Hide resolved
tests/source/issue_5533.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@ytmimi ytmimi left a comment

Choose a reason for hiding this comment

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

Thanks for your first contribution to rustfmt 🎉

See my inline comments for thoughts on how we can simplify the PR. Let me know if you have any questions.

src/comment.rs Outdated Show resolved Hide resolved
src/comment.rs Outdated Show resolved Hide resolved
src/comment.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@ytmimi ytmimi left a comment

Choose a reason for hiding this comment

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

Thanks for the follow up!

I still believe is_doc_comment is the only boolean we need to include in our check to force code execution to move to light_rewrite_comment. I could be missing something, and if we need to check both is_doc_comment and style.is_doc_comment could you please explain why. The comment is helpful and I liked that you kept it 👍🏼

@pan93412
Copy link
Contributor Author

pan93412 commented Sep 8, 2022

Thanks for the follow up!

I still believe is_doc_comment is the only boolean we need to include in our check to force code execution to move to light_rewrite_comment. I could be missing something, and if we need to check both is_doc_comment and style.is_doc_comment could you please explain why. The comment is helpful and I liked that you kept it 👍🏼

I have reverted it. However, why did L384 do such a double check?

rustfmt/src/comment.rs

Lines 378 to 385 in 8919fd3

rewrite_comment_inner(
first_group,
block_style,
style,
shape,
config,
is_doc_comment || style.is_doc_comment(),
)?

Seems like this code had been refactored before, and I don't know why they wrote it. Besides, even when I removed the determination, all the tests were still passed.

image

@pan93412 pan93412 requested a review from ytmimi September 8, 2022 03:13
@ytmimi
Copy link
Contributor

ytmimi commented Sep 8, 2022

why did L384 do such a double check?

That decision predates my time with the project. My best guess is that there was a time when both were necessary to be absolutely sure we were rewriting a doc comment. Now that we have rewrite_comment and rewrite_doc_comment as our top level comment rewriting functions it's easier to differentiate what kind of comment we're rewriting.

Seems like this code had been refactored before, and I don't know why they wrote it. Besides, even when I removed the determination, all the tests were still passed.

It's might be the case that style.is_doc_comment() is no longer needed, but it's not hurting us right now, so we'll keep it for the time being.

Copy link
Contributor

@ytmimi ytmimi left a comment

Choose a reason for hiding this comment

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

Thank you for your help on this! I think we're good to go here but will hold off on merging to give @calebcartwright a chance to take a look.

@ytmimi
Copy link
Contributor

ytmimi commented Oct 25, 2022

@pan93412 I noticed that this PR also resolves #5568 so I added a test case on your branch to validate that

@pan93412
Copy link
Contributor Author

@pan93412 I noticed that this PR also resolves #5568 so I added a test case on your branch to validate that

Thanks!

@lopopolo
Copy link

Hey folks, I think this PR has the ready to merge label and it resolves several issues with formatting comments. What else needs to be done to get this merged?

@ytmimi
Copy link
Contributor

ytmimi commented Sep 11, 2023

@pan93412 thanks again for your help on this one. This fixes a few issues so I'm going to merge.

Diff check job ran successfully ✅

@ytmimi ytmimi merged commit 18737dd into rust-lang:master Sep 11, 2023
27 checks passed
@mightyiam
Copy link

Thank you.

@ytmimi ytmimi added release-notes Needs an associated changelog entry and removed pr-ready-to-merge labels Sep 12, 2023
@ytmimi ytmimi removed the release-notes Needs an associated changelog entry label Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants