Open
Description
Sample code:
fn main() {
w(
thing,
0, // thing2
thing3,
long_thing4, // acomment
long_thing4, // bcomment
long_thing4, // ccomment
0, // another
0, // comment
thing5,
long_thing6,
thing7,
0, // yet another comment
);
}
rustfmt turns this into:
fn main() {
w(
thing,
0, // thing2
thing3,
long_thing4, // acomment
long_thing4, // bcomment
long_thing4, // ccomment
0, // another
0, // comment
thing5,
long_thing6,
thing7,
0, // yet another comment
);
}
Notice that // another
and // comment
got indented to visually align with the previous three comments.
This has multiple issues:
- rustfmt should not, in general, be visually aligning anything; its defaults normally block-align everything, per Alignment versus non-aligning indentation style-team#8 .
- In this specific case, rustfmt has made the code less readable by doing so, moving comments away from the code they comment (
0,
) to align it with an unrelated comment, while leaving other comments in the same function call untouched. The alignment misleadingly suggests some relationship between the comments or the arguments, which doesn't exist.
I would expect rustfmt to always leave same-line comments one space away from the code they comment.