rust-lang / rustfmt

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

Comment after last || branch in an if clause is forced to a separate line #6207

Open nc7s opened 3 months ago

nc7s commented 3 months ago

This code:

if lower.contains("expiry date:")
|| lower.contains("expires:") /* .am, .br, .dk, .edu, .is, .lt, .se, .ua */
|| lower.contains("expire:") /* .ar, .cz */
{
    // ...
}

is formatted to:

if lower.contains("expiry date:")
|| lower.contains("expires:") /* .am, .br, .dk, .edu, .is, .lt, .se, .ua */
|| lower.contains("expire:")
/* .ar, .cz */
{
    // ...
}

Supposedly rustfmt is assuming the comment between if and { is comment for the entire if clause. Ideally it should take || into account and take the comment before { as comment for the last || branch. (Probably also &&)