rust-lang / rust-lang/rustfmt

rustfmt gives up on code with moderate nesting, destructuring closure arg, and nested return type

Open
#7,012 1 comment 0 reactions 1 assignee View on GitHub

@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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.