Closed antonilol closed 2 months ago
The trailing whitespace issue is a result of not handling comments in binary operators. https://github.com/rust-lang/rustfmt/issues/3591#issuecomment-1190502872. rustfmt leaves the code as is to prevent it from removing the comment. If you remove the comment you'll see that rustfmt properly formats this:
fn fn1() {
#[derive(PartialEq)]
struct Struct {
looooooooooooooong_field_name: u8,
}
if None
== Some(Struct {
looooooooooooooong_field_name: 1,
})
&& true
{
todo!();
}
}
Also going to close this one since it's effectively a duplicate of #3591 and #3167
Reproducer:
(This is a minimal example of the format error made from real code, this is why there is a nonsensical
None == Some(...)
comparison,&& true
and atodo!()
)Trying to use
rustfmt
(throughcargo fmt
) on this results in an error and the code being partially formatted.cargo fmt --check
result:I don't know if the long field name has anything to do with this, but the comment certainly does, as removing it will make it format correctly.
Removing the trailing space manually will make
rustfmt
not format but still return with exit code 0.