rust-lang / rust-lang/rustfmt

Bad formatting for nested tuple field accesses on `style_edition` < 2024 when the accesses are formatted on different lines.

Open
#6,433 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-2015-to-2021-style-edition A-chains C-bug I-poor-formatting X-impacts-stable-default-format
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

The following is output of rustfmt:

fn f() {
    x.f()
        .0
         .0
        .aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa();
}

Note that the second .0 is offset by a single space. I know that this is because of compatibility with old rustc versions that lexed .0.0 as a float (i.e. https://github.com/rust-lang/rustfmt/issues/4355#issuecomment-723764276).

However, in this case, the additional space is not needed -- they are on different lines (and in fact have multiple spaces just because of the indentation).

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 running rustfmt on the nested tuple-field example in the issue with style_edition below 2024, then trace the formatting path for chained field accesses. Done means the second .0 is not given the extra one-space offset when accesses are placed on different lines, while existing float-lexing compatibility remains intact.

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
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.