Formatting panics whit a trailing whitespace.
Closed this issue · 1 comments
FabienTregan commented
formatting this code fails on my nightly toolchain (rustfmt 1.8.0-nightly (03ee484519 2024-11-18)
) and with cargo-fmt build from current source code #78aa72f9 ) :
ffn main() {
let a = //.
// there is a white space after the `b` next line. Without it, cargo-fmt won't panic. If this comment is on next line after `b `, cargo-fmt won't panic. If comment on previous line is removed, carfo-fmt won't panic. This comment can be removed, cargo-fmt still panics.
b
;
}
Trace:
...:~/code/bugreport-rustfmt$ ../rustfmt/target/release/cargo-fmt --version
rustfmt 1.8.0-nightly (03ee484519 2024-11-18)
...:~/code/bugreport-rustfmt$ ../rustfmt/target/release/cargo-fmt
error[internal]: left behind trailing whitespace
--> /home/fabien/code/bugreport-rustfmt/src/main.rs:3:3:6
|
3 | b
| ^
|
warning: rustfmt has failed to format. See previous 1 errors.
ytmimi commented
The internal errors are more like warnings than panics. They're rustfmts way of telling the developer "hey I couldn't format this piece of code". Generally, it would be a bug for rustfmt to add trailing whitespace, but in this case trailing whitespace already exists in the source code and rustfmt is warning the developer that they need to remove that whitespace themselves.
Also, rustfmt fails to format this code because it doesn't handle comments between the =
and the rhs
expression in a let statement
.