Skip to content

Not fixing indentation in long statement with multiple indentation levels and long string literals #4316

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
faern opened this issue Jul 10, 2020 · 2 comments

Comments

@faern
Copy link

faern commented Jul 10, 2020

Input

fn create_app() -> App {
    let mut app = App::new("A program name")
                .about("A program that does stuff to computers")
        .arg(
            Arg::with_name("disable_foo_bar")
            .long("disable-foo-bar")
            .help("Disable all the foos in the bar. Prevents things from going all baz on you for example")
            );
    app
}

Output

Nothing changes

Expected output

I expect the indentation of the .about(...), .long(...) and .help(...) as well as the final ); to be fixed. But they are not.

It all works as expected if the string passed to .help(....) is shorter.

fn create_app() -> App {
    let mut app = App::new("A program name")
        .about("A program that does stuff to computers")
        .arg(
            Arg::with_name("disable_foo_bar")
                .long("disable-foo-bar")
                .help("Disable all the foos in the bar. Prevents things from going all baz on you for example")
        );
    app
}

Meta

  • rustfmt version: Tested on both rustfmt 1.4.16-stable (939e164 2020-06-11) and rustfmt 2.0.0-rc.2-nightly (2c39e809 2020-07-10)
  • From where did you install rustfmt?: 1.4.16 via the default component via rustup. 2.0.0.-rc.2 from the git master branch today.
@ayazhafiz
Copy link
Contributor

Maybe a dupe of #4183?

@calebcartwright
Copy link
Member

Yeah this is a duplicate of several issues, all driven by rustfmt's current behavior wherein if any single chain item exceeds max_width then the entire chain is left unformatted.

The general consensus/desire seems to be to have rustfmt format the chain anyway (and just let the problematic item(s) exceed the width). I spent some time a while ago fighting this and had a semi-working fix though I was somewhat unhappy with my implementation attempt and dropped it 😄

Part of the challenge with carrying on with formatting the entire chain is dealing with certain combinations of indent_style and where the long item is within the chain. For example when indent_style is Visual and the long chain item is the parent or first item, you can end up with a formatted result that's far worse than the original.

Anyway, thanks for reporting this @faern but I'm going to close this given the dupe nature. Feel free to track #4183!

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