Skip to content

Feature request: option for rustfmt to leave line breaks alone #5085

Closed
@ghost

Description

Rustfmt currently considers itself responsible for breaking long lines and un-breaking short broken lines. It's approach to doing so seems to be that if a statement can't fit on 1 line, every single dot-separated part of the statement must get its own line, even if some of them are very small and would look better together. One example is https://lemmy.ml/post/88273, but I see it do this kind of thing constantly. Meanwhile if the max line length is increased enough to prevent it from doing this, it un-breaks everything to stuff it onto 1 line rather than preserving statements that were hand-formatted onto 2 or 3 lines.

Rather than modifying its line-break behavior or adding more options to control it, what I'd like to see is just an option that makes rustfmt consider line breaks to not be its responsibility - it would still apply other formats, such as trailing commas, brace style, import organization, and binop separator stuff, but would not break or un-break lines of code due to length. This is, as far as I can tell, how the Go formatter works, and I have never seen the Go formatter be anything but helpful.

Edit: Another case is when rustfmt breaks a long let binding onto 2 lines:

	let message =
		e!(pending.first(), "received handshake complete but we have no message to send", ());

As you can see, the line is quite long and a good candidate for breaking, but rustfmt's decision to break it at the = sign means that the brunt of the line isn't broken and is still very long and noisy. If I hand-modify it to break after pending.first(), instead of at the = sign, rustfmt reformats it to the above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions