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

Parser does not stop early enough if keyword is found instead of ident #28439

Closed
nagisa opened this issue Sep 16, 2015 · 6 comments
Closed

Parser does not stop early enough if keyword is found instead of ident #28439

nagisa opened this issue Sep 16, 2015 · 6 comments

Comments

@nagisa
Copy link
Member

nagisa commented Sep 16, 2015

For

enum A {
    enum A
}

and for

struct A {
    mod A
}

2 errors are emitted for each

test.rs:2:5: 2:9 error: expected identifier, found keyword `enum`
test.rs:2     enum A
              ^~~~
test.rs:2:10: 2:11 error: expected one of `(`, `,`, `=`, `{`, or `}`, found `A`
test.rs:2     enum A
                   ^

and

test.rs:2:5: 2:8 error: expected identifier, found keyword `mod`
test.rs:2     mod A
              ^~~
test.rs:2:9: 2:10 error: expected `:`, found `A`
test.rs:2     mod A
                  ^

2nd error should not happen.

@nagisa
Copy link
Member Author

nagisa commented Sep 16, 2015

Note that neither of these print a

error: aborting due to previous error

which would be a case if it terminated in properly.

@nagisa
Copy link
Member Author

nagisa commented Sep 16, 2015

More:

test.rs:2:9: 2:12 error: expected identifier, found keyword `mod`
test.rs:2     let mod hello;
                  ^~~
test.rs:2:13: 2:18 error: expected one of `:`, `;`, `=`, or `@`, found `hello`
test.rs:2     let mod hello;
                      ^~~~~

@matklad
Copy link
Member

matklad commented Sep 16, 2015

The problem is that check_strict_keywords, unlike check_reserved_keywords, does not return a PResult. In rustc, this function is used only once in parse_indent. However, this is a public fn, so it might be used outside rustc.

Is it safe to change this function interface?

@nagisa
Copy link
Member Author

nagisa commented Sep 16, 2015

All functions exposed from the rustc libraries are unstable.

matklad added a commit to matklad/rust that referenced this issue Sep 16, 2015
fixes rust-lang#28439

The signature of public `check_strict_keywords` is changed.
@matklad
Copy link
Member

matklad commented Sep 16, 2015

I wonder whether this is a bug or an expected behavior.

There is a test parse-fail/keywords-followed-by-double-colon:

fn main() {
    struct::foo();  //~ ERROR expected identifier
    mut::baz(); //~ ERROR expected identifier
}

Looks like reporting two errors here is a good thing.

nagisa added a commit to nagisa/rust that referenced this issue Sep 17, 2015
@alexcrichton
Copy link
Member

Discussed on #28444, and the conclusion was that this is currently intended behavior, so closing as working-as-intended.

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 a pull request may close this issue.

3 participants