-
Notifications
You must be signed in to change notification settings - Fork 927
Poor formatting of long method call chain with use_small_heuristics="Max"
#4678
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
Comments
I agree with you in the abstract, but practically speaking I'm not sure there's much we can really do. Even as minor/preferential as such a change may seem to some in this particular case, it would still be an explicit violation of our formatting stability guarantee which has always been a non-starter. Additionally, the wrapping of the closing paren is part of a last ditch effort to still be able to format while staying within the max_width constraints, and there's plenty of non-chain specific cases where this happens (such as heavy indentation, really long idents, etc.) By overriding the small heuristics option to Max you're basically opting out of letting rustfmt do the chain wrapping here and asking it to stretch the one-line chain til the very end. While I suppose we could do something like a fall back reformatting the entire chain, I suspect it would be rather fiddly (chains are probably the most complicated to format). The formatting of that particular chain wouldn't be my preference either, but the result is at least consistent and predictable, especially given the Max heuristics value. Maybe some minor refactoring could help reduce the indention levels or single line chain run? |
Indeed... rust-lang/rust@cec83b5 (rust-lang/rust#81546 (commits)) |
@calebcartwright can this be closed? |
Seems like while the status quo isn't great, there's not really a better option, so I'll close this. Thanks for the detailed explanation! |
The full input is quite long so I posted it at the bottom of this issue (it's extracted from rust-lang/rust#81546). The key part is:
Input
Output
The output is poorly formatted. The issue occurs with the
use_small_heuristics = "Max"
config option (because the code is fromrust-lang/rust
). The first line of the output is 99 characters, so there's no more space for the)
and a newline is added. In this case, I think rustfmt should forget about fitting it on one line and just fall back to the default behavior, which is:Another approach could work as well, I'm just suggesting that one since it's the behavior without this config option set.
Full Input
Meta
rustfmt 1.4.32-nightly (216a6430 2021-01-16)
The text was updated successfully, but these errors were encountered: