rustfmt gives up on code with moderate nesting, destructuring closure arg, and nested return type
Open
@saberoueslati is already working on this.
Since Aug 6, 2026.
A-call-chains
I-poor-formatting
I-poor-indentation
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Summary
I tried to format this code:
fn test() {
if outer {
if inner {
if even_more_inner {
let items = page
.into_iter()
.map(
|list_media_response::ListEntry {
cdn,
media_id,
length,
}|
-> Result<_, RequestError<BackupAuthCredentialRejected>> {
Ok(ListMediaItem {
cdn,
media_id,
object_length: length,
})
},
)
.try_collect()?;
}
}
}
}
Expected behavior
I expected to see the final try_collect() line align to the others.
Actual behavior
Instead, nothing changed. It does format correctly if I remove the closure return type.
(Previously filed as #7010, but I misunderstood what exactly was going wrong and it was prematurely closed.)
Configuration
rustfmt cli options used:
$ rustfmt --config=max_width=100
Meta
Reproduces in both rustfmt 1.9.0-stable (8bab26f4f6 2026-07-14) and rustfmt 1.10.0-nightly (11177f2235 2026-08-02).
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.
Assessment
This issue has not been assessed yet.