-
Notifications
You must be signed in to change notification settings - Fork 925
Exclude block-style comments in wrap_str/filter_normal_code check #4668
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
Comments
Looking at this : rustfmt/tests/source/comment.rs Lines 47 to 51 in 257311c
I am wondering what should be the desirable formatted result of the snippet below:
I personally think that
The following is the formatted code that I would expect:
But currently, rustfmt gives
|
That shouldn't be happening by default, and I'm unable to reproduce this. Are you formatting that snippet with |
You are right! rustfmt/tests/source/comment.rs Lines 1 to 3 in 257311c
In order to test |
Excellent thanks! |
Add idempotent tests for wrapping block-style comment
Add idempotent tests for wrapping block-style comment
Add idempotent tests for wrapping block-style comment
…ustfmt 2 (rust-lang#4668) Add idempotent test cases
…ustfmt 2 (rust-lang#4668) Add idempotent test cases
@calebcartwright Can this issue be closed, now that #4720 has been merged? |
Thank you for the question, but no I don't want to close it until #4758 is merged |
There's a utility function,
wrap_str
, used in various locations throughout the rustfmt codebase which does some checks against a string of formatted code, including whether each line in the string will fit within the width constraints.The width check is supposed to exclude comments, and does so successfully for line-style comments (e.g.
// foo bar
). However, there is an issue where it does not exclude block-style comments (e.g./* foo bar */
).The code that handles sorting out comments can be found in the comments.rs file:
rustfmt/src/formatting/comment.rs
Lines 1613 to 1629 in 79c3696
and this would need to be extended to exclude block-style comments as well. Remember that multi-line block style comments are a possibility, so that needs to be accounted for as well, though happy to accept improvements that cover single-line block style comments.
The changes should include tests, for example additional unit tests like the existing ones for
filter_normal_code
:rustfmt/src/formatting/comment.rs
Lines 1984 to 1999 in 79c3696
Additionally, it would be beneficial to include the standard system/idempotence tests with an input file (
tests/source/...
) that contains snippets that result in the above code paths getting hit, such as a chain that contains a block-style comment that exceeds max_width, along with a target/output file (tests/target/...
) that shows the resultant formatting.The text was updated successfully, but these errors were encountered: