Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected arrow indent change in trait methods with Rust edition 2024 #6482

Open
EFanZh opened this issue Feb 21, 2025 · 4 comments
Open

Unexpected arrow indent change in trait methods with Rust edition 2024 #6482

EFanZh opened this issue Feb 21, 2025 · 4 comments

Comments

@EFanZh
Copy link

EFanZh commented Feb 21, 2025

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?

@ytmimi
Copy link
Contributor

ytmimi commented Feb 21, 2025

What version of rustfmt are you using? When I build and run rustfmt from source (version: rustfmt 1.8.0-nightly (5619b64 2025-02-12)), I get the same output for all edition values. So I'd say this is expected.

running cargo run --bin rustfmt -- --edition={edition-value} for all editions (2015, 2018, 2021, 2024) all produce the same output:

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

@ytmimi ytmimi added the needs-mcve needs a Minimal Complete and Verifiable Example label Feb 21, 2025
@EFanZh
Copy link
Author

EFanZh commented Feb 22, 2025

@ytmimi: rustfmt 1.8.0-stable (4d91de4e48 2025-02-17) which is provided by Rust 1.85 stable toolchain. You can reproduce the result using the playground link I provided above by selecting different editions and run the Rustfmt tool.

@ytmimi ytmimi removed the needs-mcve needs a Minimal Complete and Verifiable Example label Feb 26, 2025
@ytmimi
Copy link
Contributor

ytmimi commented Feb 26, 2025

I realize now that setting --edition was a false negative. I should have been setting --style-edition. With that config I was able to reproduce the issue. I believe the PR that introduced that change was #3731, which has been part of the codebase for quite some time.

@ytmimi
Copy link
Contributor

ytmimi commented Feb 26, 2025

Based on the Style Guild section for function definitions this formatting doesn't seem correct to me. I'd expect something like this:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants