If there is a multi-line comment after the last pattern in the match expression and it is terminated by a comma, the match expression cannot be formatted.
Also, if a line containing only spaces is found in the match expression, rustfmt will print an internal error and warning.
Occurs in both stable and nightly. The version is as follows.
$ rustfmt --version && rustfmt +nightly --version
rustfmt 1.4.11-stable (1838235 2019-12-03)
rustfmt 1.4.11-nightly (1838235 2019-12-03)
fn f() {β
let x = 0;β
match x {β
0 => {}β
β
β
1 => {}β
_ => {}β
β
β
// fooβ
// barβ
}β
}β
fn f() {β
let x = 0;β
match x {β
0 => {}β
β
1 => {}β
_ => {} // fooβ
// barβ
}β
}β
fn f() {β
let x = 0;β
match x {β
0 => {}β
β
β
1 => {}β
_ => {}β
β
β
// fooβ
// bar,β
}β
}β
The space line can be anywhere in the match expression.
fn f() {β
let x = 0;β
match x {β
β
0 => {}β
β
2 => {}β
_ => {}β
β
// fooβ
// bar,β
β
}β
}β
$ rustfmt +nightly ./test.rs
error[internal]: left behind trailing whitespace
--> test.rs:4:4:0
|
4 |
| ^^^^^^^^
|
error[internal]: left behind trailing whitespace
--> test.rs:6:6:0
|
6 |
| ^^^^^^^^
|
error[internal]: left behind trailing whitespace
--> test.rs:9:9:0
|
9 |
| ^^^^^^^^
|
error[internal]: left behind trailing whitespace
--> test.rs:12:12:0
|
12 |
| ^^^^^^^^
|
warning: rustfmt has failed to format. See previous 4 errors.
Yikes! This is reproducible on master/v2.0.0-rc.1-nightly as well
I now understand that the internal error "left behind trailing whitespace" is output as a result of the validation of a piece of code that failed to format and is not the essence of this issue, sorry.
Most helpful comment
Yikes! This is reproducible on master/v2.0.0-rc.1-nightly as well