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

Parse box keyword in patterns below top-level #1722

Merged
merged 2 commits into from
Aug 22, 2019

Conversation

ecstatic-morse
Copy link
Contributor

@ecstatic-morse ecstatic-morse commented Aug 22, 2019

This extends the parser to handle patterns like if let Some(box x) = ... where the box keyword is not at the top-level. The last line of the added test caused a ParseError. This is a variant of #1412 which was not fixed by #1414.

I'm not familiar with rust-analyzer, otherwise I would fix this as well 😄.

@matklad
Copy link
Member

matklad commented Aug 22, 2019

Looks like BOX_KW is missing from PATTERN_FIRST

@ecstatic-morse
Copy link
Contributor Author

@matklad This does indeed fix the problem. Is there a way to bless parser test output?

@matklad
Copy link
Member

matklad commented Aug 22, 2019

THhere's a magical REWRITE constant somehwere

@ecstatic-morse ecstatic-morse changed the title Add (failing) test for nested box pattern Parse box keyword in patterns below top-level Aug 22, 2019
@matklad
Copy link
Member

matklad commented Aug 22, 2019

bors r+

Thanks!

bors bot added a commit that referenced this pull request Aug 22, 2019
1722: Parse `box` keyword in patterns below top-level r=matklad a=ecstatic-morse

This extends the parser to handle patterns like `if let Some(box x) = ...` where the `box` keyword is not at the top-level. The last line of the added test caused a `ParseError`. This is a variant of #1412 which was not fixed by #1414.

~~I'm not familiar with `rust-analyzer`, otherwise I would fix this as well 😄.~~

Co-authored-by: Dylan MacKenzie <ecstaticmorse@gmail.com>
@bors
Copy link
Contributor

bors bot commented Aug 22, 2019

Build failed

@ecstatic-morse
Copy link
Contributor Author

Oops, forgot to include the changes to the inline test as well. Should be ready to go once travis is green.

@matklad
Copy link
Member

matklad commented Aug 22, 2019

bors r+

No need to wait for travis when we have bors!

bors bot added a commit that referenced this pull request Aug 22, 2019
1722: Parse `box` keyword in patterns below top-level r=matklad a=ecstatic-morse

This extends the parser to handle patterns like `if let Some(box x) = ...` where the `box` keyword is not at the top-level. The last line of the added test caused a `ParseError`. This is a variant of #1412 which was not fixed by #1414.

~~I'm not familiar with `rust-analyzer`, otherwise I would fix this as well 😄.~~

Co-authored-by: Dylan MacKenzie <ecstaticmorse@gmail.com>
@bors
Copy link
Contributor

bors bot commented Aug 22, 2019

Build succeeded

@bors bors bot merged commit 3e14b16 into rust-lang:master Aug 22, 2019
@ecstatic-morse
Copy link
Contributor Author

ecstatic-morse commented Aug 22, 2019

Ugh, apparently this doesn't fix cases where a box pattern appears in conjunction with a struct or enum pattern like Some(box Struct { field: 0 }).

@matklad
Copy link
Member

matklad commented Aug 22, 2019

Hm, yeah, box at the moment is parsed as a BindPat, that is, stuff like ref mut x. But it obviously should be a completely separate pat kind, as rhs is not restricted to an identifier. To fix this, you'll need to add PAT_BOX to grammar.ron's nodes secion, PatBox to ast section, and to Pat variants. The ast types can be regenrated by cargo gen-syntax. Than the parsing of patterns should be fixed.

@ecstatic-morse
Copy link
Contributor Author

Okay, I'll look into this. It might take longer than an hour though 😃

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.

2 participants