You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fnfn1(){#[derive(PartialEq)]structStruct{looooooooooooooong_field_name:u8,}ifNone
== Some(Struct{looooooooooooooong_field_name:1,})
&&
// removing this comment makes it format as usualtrue{todo!();}}
(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 a todo!())
Trying to use rustfmt (through cargo fmt) on this results in an error and the code being partially formatted.
cargo fmt --check result:
Diff in /tmp/rustfmt_bug/src/lib.rs:4:
looooooooooooooong_field_name: u8,
}
-
if None
== Some(Struct {
looooooooooooooong_field_name: 1,
error[internal]: left behind trailing whitespace
--> /tmp/rustfmt_bug/src/lib.rs:9:9:74
|
9 | looooooooooooooong_field_name: 1,
| ^
|
warning: rustfmt has failed to format. See previous 1 errors.
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.
The text was updated successfully, but these errors were encountered:
The trailing whitespace issue is a result of not handling comments in binary operators. #3591 (comment). 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:
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.The text was updated successfully, but these errors were encountered: