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
I ended up with the following code, which will fail to format.
fnmain(){let x = 1234// important command!
+ 567;println!("x: {}", x);}
The code compiles and runs correctly.
Cargo is also unable to format this code:
❯ cargo fmt
error[internal]: left behind trailing whitespace
--> /tmp/testing_rust/src/main.rs:2:2:17
|
2 | let x = 1234
| ^
|
warning: rustfmt has failed to format. See previous 1 errors.
The problem does not occur and the formatting works if I move the comment out of the multiline addition.
fnmain(){// important command!let x = 1234
+ 567;println!("x: {}", x);}
I can see that this may not be good code style, but it should not cause the file formatting to fail.
Thanks for reaching out. This is a duplicate of #3167.
rustfmt doesn't handle comments in the middle of binary expressions very well. Instead of removing the comment, rustfmt opts to leave the entire AST node unformatted. In this case your original code snippet had trailing whitespace that rustfmt was unable to remove given that it couldn't rewrite the binary expression, and the only way to prevent the warning is to manually remove the whitespace.
I ended up with the following code, which will fail to format.
The code compiles and runs correctly.
Cargo is also unable to format this code:
The problem does not occur and the formatting works if I move the comment out of the multiline addition.
I can see that this may not be good code style, but it should not cause the file formatting to fail.
rustfmt version: 1.6.0-nightly (28eb857 2023-08-12)
rustc version: 1.73.0-nightly (28eb857b9 2023-08-12)
relevant settings: none
The text was updated successfully, but these errors were encountered: