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

Bad parse error message for missing alt close brace #2354

Closed
catamorphism opened this issue May 4, 2012 · 8 comments
Closed

Bad parse error message for missing alt close brace #2354

catamorphism opened this issue May 4, 2012 · 8 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST

Comments

@catamorphism
Copy link
Contributor

In this code:

fn foo() {
  match Some(x) {
      Some(y) { fail!(); }
      None    { fail!(); }
}

fn bar() {
    let mut i = 0;
    while (i < 1000) {}
}

fn main() {}

foo is missing the close brace for the alt, but the resulting parse error message is very unhelpful:

src/test/compile-fail/bad.rs:12:13: 12:13 error: unexpected token: '<eof>'
src/test/compile-fail/bad.rs:12 fn main() {}
                                                                   ^

It would be much more helpful to report the error at the location where the un-closed brace was (in this case, after the alt in foo). I don't know how easy it would be to do with the current parser, though.

@nikomatsakis
Copy link
Contributor

I have often wanted this too, though I imagine it is quite hard to correctly decide which brace is the unclosed one. After all, if you put a } at the end of the file, this would be perfectly valid Rust. The only way I can see to decide that the alt is at fault is through a heuristic based on the indentation---which would be quite useful! Something like missing close brace, most likely here.

catamorphism added a commit that referenced this issue May 7, 2012
@kud1ing
Copy link

kud1ing commented May 21, 2012

Maybe duplicate of #643

@nikomatsakis
Copy link
Contributor

The example in #643 is considerably easier than this one.

@kud1ing
Copy link

kud1ing commented May 21, 2012

@nikomatsakis: Do you mean it does not cover the same issue? Isn't the underlying problem "we don't know where the missing brace is, until we hit EOF" the same?

@emberian
Copy link
Member

$ rustc foo.rs
foo.rs:12:11: 12:12 error: file ended with unbalanced delimiters
foo.rs:12 fn main() {}
                     ^

Is the current error.

@graydon
Copy link
Contributor

graydon commented Jul 18, 2013

Updated code during triage. I get the same error @cmr is seeing now, which is not bad but we could possibly do better if we pointed to, say, the current still-open delimiter. It might not be the unbalanced one, but it's a place to point the user at least.

@catamorphism
Copy link
Contributor Author

(bug triage) Milestone looks right; carry on.

@ghost ghost assigned catamorphism Oct 2, 2013
@catamorphism
Copy link
Contributor Author

I'm getting annoyed with this enough to want to fix it. For me, the issue comes up pretty often when I do a merge and accidentally delete a brace, and then it can be quite a while before I see the compile error and I've forgotten what part of the code I edited.

It doesn't seem like it would be impossible to keep a stack of open delimiters and refer to their spans in the error message. In any case, I'm going to try to fix this in my next spare moment.

bors added a commit that referenced this issue Oct 8, 2013
r? anybody It's more helpful to list the span of each open delimiter seen so far
than to print out an error with the span of the last position in the file.

Closes #2354
@catamorphism catamorphism removed their assignment Jun 16, 2014
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
Fix README typo

"behaivours" -> "behaviours".
Just something I noticed while reading
celinval added a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
It looks like the other changes done by rust-lang#2311 to the release docker file were not as harmless as I thought. This change reverts them to fix the release action.
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 A-parser Area: The parsing of Rust source code to an AST
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants