Description
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.