Skip to content

Why would rustfmt change "multiple child in one line" to multiple lines? #3957

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
CliffHan opened this issue Dec 8, 2019 · 2 comments
Closed

Comments

@CliffHan
Copy link

CliffHan commented Dec 8, 2019

Before "cargo fmt":

    if !arc_manager.lock().unwrap().config.condition.function_enabled {
        return;
    }

The length was 72, and after "cargo fmt":

    if !arc_manager
        .lock()
        .unwrap()
        .config
        .condition
        .function_enabled
    {        
        return;
    }
@calebcartwright
Copy link
Member

Hi @CliffHan - There are other factors rustfmt takes into consideration for formatting beyond just the line length.

Based on the rustfmt config options, there are additional width heuristics internally calculated which set an upper limit on the max length for things like attributes, functions, as well as chains like in your snippet.

Even though the length of the chain in your snippet does not exceed the max_width config value, it is still being wrapped to multiple lines because the length exceeds the calculated max chain width allowed on a single line.

If you'd really prefer to keep the original formatting of your chain on one line then you have a few options:

  • increase the max_width value in your rustfmt config file
  • leverage the use_small_heuristics config option (try using Off or Max) which is used for those internal max calculations.
  • have rustfmt ignore that block altogether via #![rustfmt::skip]:
   #![rustfmt::skip]
    if !arc_manager.lock().unwrap().config.condition.function_enabled() {
        return;
    }

@CliffHan
Copy link
Author

CliffHan commented Dec 9, 2019

Thanks for you explanation

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

No branches or pull requests

2 participants