Skip to content

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

Description

@jrose-signal

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).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions