rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
6.03k stars 889 forks source link

Allow forcing line breaks #2990

Open vadimcn opened 6 years ago

vadimcn commented 6 years ago

Sometimes I want to insert line breaks in long expressions to better reflect their logical structure. With clang-format this is possible by inserting a line-end comment at the desired break point (even if it's just an empty //).
As far as I can see, rustfmt just stops formatting such expressions altogether (is this a bug?). It strips empty comments, but that can be worked around with something like //..

nrc commented 6 years ago

Rustfmt can't find comments everywhere so this isn't going to work. The solution is long term and involves having spans for comments either in the AST or our own version of the AST, neither is going to happen soon, unfortunately.

BartMassey commented 2 years ago

Is there a rustfmt attribute to allow it to format an item except for changing the given line breaks? If not, could there be? Right now I'm using #[rustfmt::skip], but I really just want rustfmt to change everything but my line breaks.