Preventing rustfmt from de-verticalizing code

As I've mentioned before, one of my personal bugbears with rustfmt is that it can force mixing functional changes with style changes.

One of the most obvious cases is in list-like code (e.g. function signatures or calls with one parameter per line, or arrays with one entry per line) where if the number of list entries becomes small enough to fit into a single line, rustfmt may force that.

This means that the removal of a single function paramter (or array entry) might result in the code being rewritten from one parameter per line to all parameters on a single line. This isn't a big deal if only one parameter remains, but it makes for a harder-to-follow diff if multiple parameters are left over.

I don't want to require verticalized code for every case, but is there any way to prevent rustfmt from de-verticalizing code that is currently written as verticalized, so long as more than one entry remains?

I don't think the current config parameters allow for something like this, but would like to be sure. If it's not currently possible, would it be reasonable as a feature request?

I think this issue is related:

AFAIK, this is an intentional design decision.

1 Like

Thanks, that's useful to read. The remarks there -- that avoiding any dependency on the original formatting is intentional -- are pretty much what I expected the answer to be. That said, I think a maximum complexity config option -- with separate values for calls and for function declarations -- could potentially be helpful here too.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.