rust-lang / rust-lang/rustfmt

Struct patterns containing `..` are sometimes formatted neither vertically nor on a single line

Open
#6,827 2 comments 0 reactions 1 assignee View on GitHub

@Souradip121 is already working on this.

Since Apr 21, 2026.

A-patterns C-bug needs-triage
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 main() {
    // case 1
    x = X { field1, field2, xx };
    let X { field1, field2, .. } = x;

    // case 2
    x = X { field1, field2x, xx };
    let X { field1, field2x, .. } = x;

    // case 3
    x = X { field1, field2, field3, xx };
    let X { field1, field2, field3, .. } = x;
}
Expected behavior

I expected each struct literal or pattern to either be kept on a single line, or formatted vertically (with each field on a separate line).

Furthermore, within each of the three cases, I expected the struct literal and struct pattern to be formatted the same way, because they had the same width in the input.

Actual behavior

Instead, Rustfmt (with default options) formats the code like this:

fn main() {
    // case 1
    x = X { field1, field2, xx };
    let X { field1, field2, .. } = x;

    // case 2
    x = X {
        field1,
        field2x,
        xx,
    };
    let X {
        field1, field2x, ..
    } = x;

    // case 3
    x = X {
        field1,
        field2,
        field3,
        xx,
    };
    let X {
        field1,
        field2,
        field3,
        ..
    } = x;
}

Cases 1 and 3 look okay, but case 2 is unexpected. The struct literal in the first line was formatted vertically, but the struct pattern in the second line was formatted neither vertically nor on a single line: the struct is split across multiple lines, but all the fields are on the same line.

Configuration

Default configuration (missing or blank rustfmt.toml).

Reproduction Steps

Format the code at the beginning of this issue with default options.

Meta

rustfmt --version:

rustfmt 1.9.0-nightly (3b1b0ef4d8 2026-03-11)

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.