Skip to content

fix(items): format comments after where using clause_shape budget - #7156

Merged
ytmimi merged 1 commit into
rust-lang:mainfrom
dbaileychess:fix-where-clause-comment-wrap
Oct 2, 2026
Merged

ytmimi merged 1 commit into
rust-lang:mainfrom
dbaileychess:fix-where-clause-comment-wrap

Conversation

@dbaileychess

@dbaileychess dbaileychess commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7148

When formatting an item with a where clause, the budget before the where keyword is throttled by the item header width (e.g., max_width - header_len).

However, comments located between the where keyword and the first predicate are indented on their own lines. They should be formatted using the full clause budget (clause_shape) rather than the throttled header budget.

Prior to this fix, comments after where were prematurely wrapped at an artificially narrow column budget derived from the header length.

Added tests/source/where-clause-comment-wrap.rs and tests/target/where-clause-comment-wrap.rs.
- Verified that the unpatched binary fails by wrapping the comment at column ~59.
- Verified that the patched binary passes without unwanted line wraps.

No LLM was used in the generation of this PR.

@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Oct 1, 2026
@dbaileychess

dbaileychess commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixes #7148

@jieyouxu

jieyouxu commented Oct 2, 2026

Copy link
Copy Markdown
Member

Fixes #7156

I think you meant another issue, since that's this PR's number 😉

@jieyouxu jieyouxu added the A-comments Area: comments label Oct 2, 2026
@dbaileychess

Copy link
Copy Markdown
Contributor Author

Thanks, that's why i shouldn't rely on autocomplete. Fixed to #7148

@ytmimi ytmimi self-assigned this Oct 2, 2026

@ytmimi ytmimi left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR. I'd like to make some tweaks to the test case.

View changes since this review

Comment thread tests/source/where-clause-comment-wrap-issue-7148.rs
@rustbot rustbot added S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels Oct 2, 2026
@rustbot

rustbot commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@ytmimi ytmimi added X-impacts-stable-formatted-code Expected formatting impact: affects stable formatted code (caution) UO-wrap_comments Unstable option: wrap_comments A-trait-bounds Area: trait bounds UO-comment_width Unstable option: comment_width and removed X-impacts-stable-formatted-code Expected formatting impact: affects stable formatted code (caution) labels Oct 2, 2026
@ytmimi

ytmimi commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Removed the X-impacts-stable-formatted-code label since you need to use the unstable wrap_comments option to reproduce the bug. This doesn't impact stable.

@dbaileychess
dbaileychess force-pushed the fix-where-clause-comment-wrap branch from 3aff0b6 to bf43b7b Compare October 2, 2026 18:40
@rustbot

This comment was marked as resolved.

@dbaileychess

This comment was marked as resolved.

@dbaileychess

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. labels Oct 2, 2026
@ytmimi

This comment was marked as resolved.

@dbaileychess
dbaileychess force-pushed the fix-where-clause-comment-wrap branch from bf43b7b to df2780a Compare October 2, 2026 18:48
@dbaileychess

This comment was marked as off-topic.

@ytmimi ytmimi left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would like us to continue adding to the test cases.

View changes since this review

Comment thread tests/source/where-clause-comment-wrap-issue-7148.rs
@rustbot rustbot added S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels Oct 2, 2026
When formatting an item with a where clause, the budget before the where
clause is throttled by the item header width. However, comments between
the `where` keyword and the first predicate are indented on their own
lines and should be formatted with the full clause budget (`clause_shape`)
rather than the throttled budget.

Pass `clause_shape` to `rewrite_comments_before_after_where` so that
comments after `where` are not prematurely wrapped.

Fixes rust-lang#7148.
@dbaileychess
dbaileychess force-pushed the fix-where-clause-comment-wrap branch from df2780a to 3297756 Compare October 2, 2026 20:28
@dbaileychess

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. labels Oct 2, 2026

@ytmimi ytmimi left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for applying the feedback!

View changes since this review

@ytmimi
ytmimi added this pull request to the merge queue Oct 2, 2026
Merged via the queue into rust-lang:main with commit 8c329c0 Oct 2, 2026
33 checks passed
@rustbot rustbot added release-notes Needs an associated changelog entry and removed S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-comments Area: comments A-trait-bounds Area: trait bounds release-notes Needs an associated changelog entry UO-comment_width Unstable option: comment_width UO-wrap_comments Unstable option: wrap_comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rustfmt wraps comments too tightly on first trait bound

4 participants