"left behind trailing whitespace" on contents of skipped item
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
I ran cargo fmt and it reported error[internal]: left behind trailing whitespace and failed to format a file. Minimal reproduction:
impl Foo {
#[rustfmt::skip]
fn foo() {
Bar
// ^ there is whitespace here
}
}
error[internal]: left behind trailing whitespace
--> /playground/src/main.rs:4:4:11
|
4 | Bar
| ^^^^^^
|
warning: rustfmt has failed to format. See previous 1 errors.
The original case was a const array of enum variants, so this is not specific to fns.
If the #[rustfmt::skip] attribute is relocated to the entire impl block then the code is (correctly) skipped silently.
Meta
This seems very similar to #2037, but that specific case has not regressed.
- rustfmt version: 1.4.25-stable (0f29ff6d 2020-11-11) or 1.4.36-nightly (2021-02-07 7de6968)
- From where did you install rustfmt?:
rustupor Rust Playground - How do you run rustfmt:
cargo fmtor Rust Playground
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report with the Rust snippet containing an item-level #[rustfmt::skip] and trailing whitespace, using cargo fmt or the Rust Playground. Trace how rustfmt handles skipped items and compare it with skipping the entire impl block; done means the skipped contents no longer produce a trailing-whitespace error while formatting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100