rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

fix: #6520, move comment above line if it would cross out the type in…

Open MarcusGrass opened this issue 5 months ago • 0 comments

… a function arg.

fixes #6520

A bit unsure about this one.

The problem is that if you have a comment that spans to the end of the line, then pushing the ty_str after it will make that ty_str part of the comment.

It's similar to this https://github.com/rust-lang/rustfmt/issues/2976 except isolates comments that do not close themselves.

There's some nuance here, since the decision has to be made where to put the comment. Putting it on top is the simplest, putting it last on the line would require making sure that nothing follows the comment.

Lastly, checking the comment style processes the span again, which is why that's only done conditionally if there is some comment there, so it shouldn't hit most cases. The alternative is a bigger refactor where either the comment style is identified before being passed down to identify_comment, or that metadata is propagated up from the caller. Neither of those options seemed nice.

MarcusGrass avatar Jun 12 '25 04:06 MarcusGrass