Skip to content

Nested blocks and functions get weird visual indent #1570

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

Closed
LunaBorowska opened this issue May 20, 2017 · 6 comments
Closed

Nested blocks and functions get weird visual indent #1570

LunaBorowska opened this issue May 20, 2017 · 6 comments

Comments

@LunaBorowska
Copy link

LunaBorowska commented May 20, 2017

I honestly don't know how to describe that one. It's like rustfmt cannot decide whether it wants to include alignment with a block to indent. Default settings (like on play.rust-lang.org).

This:

fn example() {
    a_very_long_function_name({some_func(1, {1})})
}

Changes into this:

fn example() {
    a_very_long_function_name({
                                  some_func(1, {
            1
        })
                              })
}
@zonyitoo
Copy link

I have encountered the same problem, which messes up the whole file!!

@nrc nrc changed the title Block expression in block expression has weird formatting Nested blocks and functions get weird visual indent May 21, 2017
@nrc nrc added the p-high label May 21, 2017
@nrc
Copy link
Member

nrc commented May 21, 2017

This looks pretty bad with the RFC formatting too:

fn example() {
    a_very_long_function_name(
        {
            some_func(
                1, {
                    1
                }
            )
        }
    )
}

There should be some elision of line breaks, but once we multi-line the second arg of the nested function, it should put the args on different lines.

@topecongiro
Copy link
Contributor

Which is expected when using RFC?

fn example() {
    a_very_long_function_name({some_func(1, {
        1
    })})
}
fn example() {
    a_very_long_function_name({
        some_func(1, {
            1
        })
    })
}
fn example() {
    a_very_long_function_name({
        some_func(
            1,
            {
                1
            },
        )
    })
}

@nrc
Copy link
Member

nrc commented May 23, 2017

I would expect both the blocks to be single-line because they are single-expression blocks, so I'd probably expect:

fn example() {
    a_very_long_function_name({ some_func(1, { 1 }) })
}

If the inner block were not, then I would expect your first example (because everything nests and in the two arg case, we keep the last arg on the same line as the prefix args). However, I would expect a space after the opening {. I'd expect the second example if the outer block had a semi-colon too. I think you'd only get the third example if the first 1 were actually very long.

@topecongiro
Copy link
Contributor

@nrc Thank you for clarifying!

@topecongiro
Copy link
Contributor

Closed via #1729.

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

4 participants