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

Better handling of missing closing or opening delimiters, well distinct by type of delimiter #138401

Open
leonardo-m opened this issue Mar 12, 2025 · 1 comment · May be fixed by #138554
Open
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@leonardo-m
Copy link

leonardo-m commented Mar 12, 2025

Code

This code is wrong, it lacks an open "(" to call abs():

pub fn foo(x: i64) -> i64 {
    x.abs)
}
fn main() {}

Current output

rustc 1.87.0-nightly gives the error messages:

error: mismatched closing delimiter: `)`
 --> ...\test.rs:1:27
  |
1 | pub fn foo(x: i64) -> i64 {
  |                           ^ unclosed delimiter
2 |     x.abs)
  |          ^ mismatched closing delimiter

error: unexpected closing delimiter: `}`
 --> ...\test.rs:3:1
  |
2 |     x.abs)
  |          - missing open `(` for this delimiter
3 | }
  | ^ unexpected closing delimiter

error: aborting due to 2 previous errors

Desired output

On this code I'd like rustc to give only one error, that says "- missing open ( for this delimiter", or something similar.

Rationale and extra context

I think rustc should consider {} () [] as totally distinct pairs of things. I think it isn't common for a programmer to mix them by mistake. It happens, but I think it happens quite less often than missing a correct pairing of { with } or ( with ) or [ with ] by mistake.

Other cases

Rust Version

rustc 1.87.0-nightly (665025243 2025-03-11)
binary: rustc
commit-hash: 6650252439d4e03368b305c42a10006e36f1545e
commit-date: 2025-03-11
host: x86_64-pc-windows-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Anything else?

No response

@leonardo-m leonardo-m added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 12, 2025
@xizheyin
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants