rust-lang / rust-lang/rustfmt

Unexpected arrow indent change in trait methods with Rust edition 2024

Open
#6,482 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-2024-style-edition I-poor-formatting
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

With the following code:

trait Foo {
    fn fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(_: ())
        -> u32;
}

The -> is indented with 4 spaces after fn with edition 2021, but with edition 2024, rustfmt will align -> with fn:

trait Foo {
    fn fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo(_: ())
    -> u32;
}

Here is a playground link for this: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=9cb2cfab404be994870455658edba6e0.

Is this change intended?

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 with the provided Rust Playground reproduction and compare rustfmt output for editions 2021 and 2024. Trace the formatting behavior for long trait method signatures and determine whether the edition-dependent arrow indentation is intentional; done means the expected behavior is decided and the issue has a corresponding regression test or documented resolution.

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.