--file-lines can trip up trailing whitespace validity check
メンテナーはふだん 1 日以内に返信
@saberoueslati がすでに取り組んでいます。
2026年8月29日 から。
評価
この issue はまだ評価されていません。
説明
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.
- 主要言語
- Rust
- スター
- 7.1k
- フォーク
- 1.2k
- 平均マージ
- 1日 4時間
- マージ済み PR(30日)
- 20
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rust-lang/rustfmt のほかの issue
-
A-config C-bug SO-print-config
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
メンテナーはふだん 1 日以内に返信
-
A-Unicode C-bug P-low
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
rust-lang/rustfmt#7210 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
-
A-imports C-bug E-hard I-non-idempotency X-impacts-stable-default-format
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
rust-lang/rustfmt#7173 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
A-comments C-bug only-with-option UO-indent_style
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Fix `first_line_width` to be tab-aware再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンA-tabs A-whitespace C-bug SO-hard_tabs
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
rust-lang/rustfmt の issue をすべて見る
似ている issue
-
bug P2
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
bug core-lang
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Windows microphone listing treats words in a device name as DirectShow labels対応中かも @Sujal-chaudhary が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
clipy-recorder/clipy#447 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
nightly-cleanup
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
max-sixty/worktrunk#4939 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信