rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Wrapping long trailing comments

Open yshui opened this issue 1 month ago • 0 comments

(from https://github.com/rust-lang/rustfmt/issues/5577#issuecomment-3539743489, sorry for the off-topic comment!)

Don't align unrelated trailing comments after items or at the end of blocks

https://github.com/rust-lang/rustfmt/issues/5577#issuecomment-1315302533

I got hit by this change. There are occasions where I do want to break a trailing comment into multiple lines. Now I can't do that because rustfmt no longer align them.

If the intention is stopping unrelated comments from being aligned, is there a way for me to indicate that those comments are indeed related?

but i want make this issue more general. right now, rustfmt is not able to wrap long trailing comments:

func(); // a really long explanation of what this function does and why it does it and why it should be called here and such and such.

desired behavior with wrap_comments=true:

func(); // a really long explanation of what this function
        // does and why it does it and why it should
        // be called here and such and such

actual behavior: nothing happens.

before style-edition=2024, i could still manually break the comment up and rustfmt will properly align the lines. after, i am no longer able to, since rustfmt will format it as:

func(); // a really long explanation of what this function
// does and why it does it and why it should
// be called here and such and such

yshui avatar Nov 18 '25 19:11 yshui