rust-lang / rust-lang/rustfmt

Incorrectly and non-idempotently modifies `..` in macro

Open
#6,300 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-comments A-macros C-bug
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Start with this:

fn a() {
    a!(b {
        c: d,
        //
        ..
    });
}

Rust rustfmt, and you get this:

fn a() {
    a!(b {
        c: d,
        //
        ..
        ..
    });
}

Run it a third time, and you get this:

fn a() {
    a!(b {
        c: d,
        //
        ....
    });
}

And then we have a fixed point.

This can cause rustfmt to break certain macro-using code. The behavior still exists if you substitute a rather than a!, and I guess it's weird if it's not idempotent, but it's a bit of an edge case since that is not syntactically valid rust anyway. But you can write fully-compilable code that exhibits this behavior when formatted with rustfmt, if you're using certain macros like assert_matches!.

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.

Research direction

Start by reproducing the minimal macro example with rustfmt and compare its output across repeated runs. Trace the formatting path for .. inside macro input, then add a regression test showing that formatting is idempotent and does not duplicate or merge the dots.

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
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.