Skip to content

Support partially formatting method chains - #6862

Draft
randomPoison wants to merge 17 commits into
rust-lang:mainfrom
randomPoison:issue-4053-file-lines-multi-line-statements
Draft

randomPoison wants to merge 17 commits into
rust-lang:mainfrom
randomPoison:issue-4053-file-lines-multi-line-statements

Conversation

@randomPoison

@randomPoison randomPoison commented Apr 14, 2026 •

Copy link
Copy Markdown
Contributor

Support formatting method chains when only part of the chain is selected with --file-lines, ensuring that only the selected parts of the chain are modified. Partially addresses #4053.

To support this I had to define how chains should be formatted when only part of the chain is selected, since short chains want to be formatted into a single line but we can't do so if only part of the chain was selected. I've opted to have partially-selected chains always be formatted as multi-line chains (i.e. one call in the chain per line, as is the case for long method chains), even if the chain as a whole would be short enough to fit in one line. This means we sometimes get different formatting when formatting the chain as a whole vs formatting only part of the chain, but that seems like the only reasonable approach to take and aligns with the desired formatting described in #4053.

Commit history isn't clean, let me know if I should squash this before it can be merged.

LLM Usage Disclosure

  • I did not use an LLM to create a change in this PR.
  • I used an LLM to create a change in this PR, and I have explained below how it was used.

I used an LLM to assist me in exploring the codebase and to write parts of the PR. LLM-written code was then reviewed and edited by me. Unfortunately I don't remember specific details about what exactly was LLM-written vs manually-written, since I initially put this PR up several months ago.

@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Apr 14, 2026
@ytmimi ytmimi self-assigned this Apr 17, 2026
@rustbot

rustbot commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (possibly #7124) made this pull request unmergeable. Please resolve the merge conflicts.

@randomPoison
randomPoison marked this pull request as draft September 21, 2026 22:11
@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 Sep 21, 2026
@randomPoison

Copy link
Copy Markdown
Contributor Author

I'm switching this to being a draft since I'd like to do another round of review on this before maintainers review it. This was the first non-trivial change I made in the repo and I'm much more familiar with rustfmt internals now, so I'd like to make sure everything looks good before taking maintainer time (especially in light of the new LLM usage policy).

@randomPoison

Copy link
Copy Markdown
Contributor Author

I've also put up #7137, which provides an alternate solution for #4053 with different semantics for how a partially-selected chain will be formatted.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants