Chains of functions with a comment on the last function do not format
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Summary
I tried to format this code:
Some(5i32)
.unwrap() // Comment
;
Expected behavior
I expected it to format to:
Some(5i32)
.unwrap() // Comment
;
Actual behavior
Instead, it didn't format it at all. Looking into it more, it appears that the issue is just as the title suggests, any chain of function calls doesn't get formatted if there's a comment on the last one. While the given example is unrealistic, the bug also occurs if there's an as cast after the chain.
Configuration
Default
Reproduction Steps
Try to format the code in the playground.
Meta
rustfmt --version:
rustfmt 1.10.0-nightly (2026-08-26 bff8e12ff5)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the example in the rustfmt playground, including the chained call with a trailing comment and the variant with an as cast. Trace the rustfmt formatting path for chained function calls; done means both cases format as expected while preserving the comment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100