Description
Sorry in advance if this is a dup! I saw #2896 and several others with this internal error but I can't tell if this is the same cause.
Describe the bug
rustfmt
produced an internal error about whitespace and exited with a non-zero exit status (which can break tooling like IDEs -- or vim integration in my case).
To Reproduce
Here's the minimum input I found that reproduced this issue:
fn f() {
async {
// Hmm.
}
}
Note that there's trailing whitespace in the first line of the async
block. Here's the result:
$ rustfmt --check tmp.rs
error[internal]: left behind trailing whitespace
--> /Users/dap/Desktop/rustfmt-issue/tmp.rs:3:3:0
|
3 |
| ^^^^
|
warning: rustfmt has failed to format. See previous 1 errors.
This is inside an otherwise empty directory, so there's no rustfmt configuration file. I tried the following simplifications, but each of these caused the problem to go away:
- Removing the line with the comment
- Changing
async
toloop
- Dropping the
async {
and}
line (moving the contents of the async block to the top level of the function)
Expected behavior
I expected the code to be reformatted like this:
fn f() {
async {
// Hmm.
}
}
and for rustfmt
to exit with status code 0.
Meta
- rustfmt version:
rustfmt 1.4.25-stable (0f29ff6d 2020-11-11)
- From where did you install rustfmt?:
rustup
- How do you run rustfmt:
rustfmt --check tmp.rs
This sounds a little bit like what's described here in #2896 but I'm not sure if it's the same or not.