rustfmt panics unecessarily due to redundant tabs->spaces logic #5431
Labels
bug
Panic, non-idempotency, invalid code, etc.
only-with-option
requires a non-default option value to reproduce
p-low
The code:
main.rs:
rustfmt.toml:
>cargo fmt
The error explained:
When rustfmt tries to replace the
\t
tab character with 100 spaces, it overflows the line. For some reason, botherror_on_line_overflow
ANDerror_on_unformatted
must betrue
for this to produce an error. Normally, this error would be pretty-printed as in the following example where the only change ishard_tabs = false
:cargo fmt
Again, this error only displays when both
error_on_line_overflow
ANDerror_on_unformatted
aretrue
.The issue:
hard_tabs
istrue
, so this error should never happen! The overflow comes from replacing tabs with100
spaces, according to thetab_spaces
option. However, tabs shouldn't be replaced with spaces according to thehard_tabs
option. It would appear that this is actually handled later on in rustfmt, because the final output of the formatter correctly has tabs. This implies that there is a part of the code that replaces tabs with spaces, but doesn't actually need to, because the result of that isn't used in the final output. Alternatively, it means that there is more logic happening down the line that replaces the100
spaces with\t
tabs before outputting. Either way, redundent work is being done, causing rustfmt to panic unnecessarily. I say unnecessarily because the file does actually get formatted. Witherror_on_line_overflow
orerror_on_unformatted
set tofalse
, or withtab_spaces
set to a smaller value, there wouldn't seem to be anything wrong.This happens on many tested versions of nightly. Only the nightly toolchain can trigger this panic because
error_on_line_overflow
anderror_on_unformatted
are marked asunstable
.The text was updated successfully, but these errors were encountered: