Skip to content

Bad formatting with closures #6382

@Jasonshengxi

Description

@Jasonshengxi

Formatting the following code produces awful results:

fn main() {
    {
        {
            {
                let result = this_is_a_quite_long_name(
                    another_long_one, 
                    &|from, to| -> LongResult<Words> {
                        () // this comment is to keep it from collapsing
                    }
                )?;
            }
        }
    }
}

it's formatted into this:

fn main() {
    {
        {
            {
                let result = this_is_a_quite_long_name(another_long_one, &|from,
                                                                           to|
                 -> LongResult<
                    Words,
                > {
                    () // this comment is to keep it from collapsing
                })?;
            }
        }
    }
}

playground: link

I can ignore it by using #[rustfmt::skip] but this behavior seems incorrect.

Activity

ytmimi

ytmimi commented on Nov 2, 2024

@ytmimi
Contributor

Likely a duplicate of one of these other closure formatting issues: https://github.com/rust-lang/rustfmt/issues?q=is%3Aissue%20state%3Aopen%20label%3Aa-closures

Paladynee

Paladynee commented on Nov 28, 2024

@Paladynee

this feels like it would go away if you set a wider character limit

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ytmimi@Jasonshengxi@Paladynee

        Issue actions

          Bad formatting with closures · Issue #6382 · rust-lang/rustfmt