Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustfmt inserts two closing brackets when missing closing paren #4466

Closed
mikecargal opened this issue Oct 11, 2020 · 0 comments · Fixed by #4472
Closed

rustfmt inserts two closing brackets when missing closing paren #4466

mikecargal opened this issue Oct 11, 2020 · 0 comments · Fixed by #4472
Assignees
Labels
a-parser bug Panic, non-idempotency, invalid code, etc.

Comments

@mikecargal
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-parser bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants