Closed as not planned
Description
$ cargo fmt --version
rustfmt 1.5.1-stable (d5a82bb 2023-02-07)
Minimal (perhaps not exactly) reproducible example:
fn main() {
pub fn example(arg: Option<f32>) -> f32 {
let Some(a) = arg else {
let b = 0.0;
return b;
};
a
}
}
Leave formatting errors (e.g. spurious whitespace) anywhere except the let-else expression (which isn't formatted, I understand to be intended behaviour), and rustfmt
crashes rather than formatting it away. It outputs this with exit code 1:
$ cargo fmt
error[internal]: left behind trailing whitespace
--> /home/jmaargh/code/eg/src/main.rs:3:3:33
|
3 | let Some(a) = arg else {
| ^
|
warning: rustfmt has failed to format. See previous 1 errors.
This appears to only happen when there is trailing whitespace left within the else
block. That is, the trailing whitespace within the else
block causes all formatting elsewhere in the file to break. If you manually "properly" format this else block by removing trailing whitespace, the error appears to go away.