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

libsyntax: stop early enough if keyword is found instead of ident #28444

Closed
wants to merge 2 commits into from

Conversation

matklad
Copy link
Member

@matklad matklad commented Sep 16, 2015

fixes #28439

The signature of public function check_strict_keywords is changed. This function is used only once in rustc in parse_ident.

This breaks 9 tests in parse-fail category, because they expect two messages instead of one. I think it's safe just to fix the tests expectations.

fixes rust-lang#28439

The signature of public `check_strict_keywords` is changed.
@rust-highfive
Copy link
Collaborator

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

Some tests now stop early, and produce only one error message
@alexcrichton
Copy link
Member

Looks like this has some regressions in the compile-fail tests which will need to be addressed.

I also think that the current behavior is fine, it's targeted at cases like:

enum Foo {
    Self(i32),
    // ...
}

In this case you'll get an error message about Self and nothing else, but the parser will keep going and try to emit more errors. In that sense I'm not 100% convinced that #28439 is indeed a bug.

@matklad
Copy link
Member Author

matklad commented Sep 17, 2015

In that sense I'm not 100% convinced that #28439 is indeed a bug.

Same for me.

Cons:

  • the parser will not recover after Self(i32)
  • a public interface is changed
  • current behaviour is changed.

Pros:

  • if we actually look at the changed tests, matklad@95a87ba, parser recovery usually leads to some obscure error like this "ERROR expected one of !, ,, ., ::, ;, ], {, or an operator, found 1". I argue that reporting only one error in such cases is much better. The caveat is that though such cases form a significant majority in tests, nothing can be said about distribution in user's code.
  • inconsistency between check_strict_keywords and check_reserved_keywords does not feel right: https://github.com/rust-lang/rust/blob/master/src/libsyntax/parse/parser.rs#L548-L549

I have no strong opinion about what is best, but I am slightly in favor of change.

@matklad
Copy link
Member Author

matklad commented Sep 17, 2015

@alexcrichton so should I repair the test (and move it to parse-fail category), or this is a won't fix?

@alexcrichton
Copy link
Member

In terms of recovering from parser errors, I think it makes the most sense to try to recover from errors that are likely to arise. For example it's expected that enum Foo { ident } is a valid declaration, so if ident is actually a keyword it may make the most sense for the parser to assume it was a bland identifier and just keep parsing as usual.

A lot of the parse-fail tests are either super old syntax or are just kinda semi-random syntax, which is bound to always give obscure parse errors. I suppose what I'm getting at is that I'm ok with obscure code giving obscure errors, it makes more sense to try to give high quality errors (and as many of them as possible) for almost-reasonable code as it's the most likely kind to be written by accident.

I also wouldn't worry too much about public interfaces here, everything is unstable so we're free to change at will.

@matklad
Copy link
Member Author

matklad commented Sep 18, 2015

So let's close the PR and the issue.

@matklad matklad closed this Sep 18, 2015
@alexcrichton
Copy link
Member

Ok, thanks regardless for the PR @matklad!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parser does not stop early enough if keyword is found instead of ident
3 participants