Closed
Description
Describe the bug
The accidental omission of a closing paren, as in:
println!("answer: {}", a_func();
causes Rustfmt to insert two closing brackets, obscuring the actual error.
To Reproduce
create main.rs
fn main() {
if true {
println!("answer: {}", a_func();
} else {
println!("don't think so.");
}
}
fn a_func() -> i32 {
42
}
run rustfmt (in my case implicitly in VS Code with the format on save capability). Result is:
fn main() {
if true {
println!("answer: {}", a_func();
}
}
} else {
println!("don't think so.");
}
}
fn a_func() -> i32 {
42
}
This results in the following errors (obscuring the actual error):
error: unexpected closing delimiter: `}`
--> src/main.rs:6:5
|
1 | fn main() {
| - this opening brace...
...
5 | }
| - ...matches this closing brace
6 | } else {
| ^ unexpected closing delimiter
error: mismatched closing delimiter: `}`
--> src/main.rs:4:9
|
3 | println!("answer: {}", a_func();
| - unclosed delimiter
4 | }
| ^ mismatched closing delimiter
error: aborting due to 2 previous errors
error: could not compile `fmt_bug`.
To learn more, run the command again with --verbose.
Expected behavior
Don't insert closing brackets, so the missing closing paren is reported as the actual error.
Meta
- rustfmt version: rustfmt 1.4.20-stable (48f6c32 2020-08-09)
- From where did you install rustfmt?: rustup
- How do you run rustfmt: VS Code Rust plugin