--file-lines can trip up trailing whitespace validity check
I maintainer di solito rispondono entro 1 giorno
@saberoueslati ci sta già lavorando.
Dal 29/8/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
rustfmt has a post-formatting validity check that looks for trailing whitespace that was left behind after formatting, and it will output errors if trailing whitespace was leftover. This will also cause tests to fail if detected in test output. This validity check is not handled correctly in combination with the --file-lines feature, which can cause the validity check to fail on unselected lines.
Summary
Consider the following Rust code:
fn foo(
first: i32, // force vertical
selected: i32,
) {
trailing();
}
Note that there is trailing whitespace on line 8.
I can use --file-lines to format just the arguments of the function (lines 2-6). If I do so, rustfmt correctly formats the arguments without touching the body of the function, but it incorrectly emits an error in the process.
Expected behavior
Formats the selected lines without error.
Actual behavior
Formats the selected lines, but produces an error about trailing whitespace on unselected lines:
error[internal]: left behind trailing whitespace
--> /home/legare/rustfmt/test.rs:6:6:12
|
6 | trailing();
| ^^^
|
warning: rustfmt has failed to format. See previous 1 errors.
Configuration
rustfmt cli options used:
rustfmt --unstable-features --file-lines '[{"file":"test.rs","range":[2,6]}]' test.rs
Meta
The issue seems to be that the post-formatting trailing whitespace check is looking at the lines specified by --file-lines without taking into account that the selected lines may have changed in length. In this case, lines 2-6 map to lines 2-4 in the formatted output, and the line with trailing whitespace gets moved to line 6. The validity check then looks for trailing whitespace on lines 2-6, even though lines 5-6 of the output do not correspond to lines selected by --file-lines, and so were not formatted.
- Lingua principale
- Rust
- Stelle
- 7.1k
- Fork
- 1.2k
- Merge medio
- 1g 4h
- PR unite (30g)
- 20
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rust-lang/rustfmt
-
A-config C-bug SO-print-config
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
-
A-Unicode C-bug P-low
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
rust-lang/rustfmt#7210 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
A-imports C-bug E-hard I-non-idempotency X-impacts-stable-default-format
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
rust-lang/rustfmt#7173 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
A-comments C-bug only-with-option UO-indent_style
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Fix `first_line_width` to be tab-awareForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. ApertaA-tabs A-whitespace C-bug SO-hard_tabs
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di rust-lang/rustfmt
Issue simili
-
bug P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
bug core-lang
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Windows microphone listing treats words in a device name as DirectShow labelsForse già presa @Sujal-chaudhary l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
clipy-recorder/clipy#447 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
nightly-cleanup
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
max-sixty/worktrunk#4939 · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno