Skip to content

"left behind trailing whitespace" on contents of skipped item #4706

Open
@kpreid

Description

@kpreid

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 (0f29ff6 2020-11-11) or 1.4.36-nightly (2021-02-07 7de6968)
  • From where did you install rustfmt?: rustup or Rust Playground
  • How do you run rustfmt: cargo fmt or Rust Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    a-rustfmt::skipbugPanic, non-idempotency, invalid code, etc.e-trailing whitespaceerror[internal]: left behind trailing whitespacep-low

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions