-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 arbitrarily complex box
patterns.
#1733
Conversation
r? @matklad |
26bba51
to
075348a
Compare
@@ -416,6 +416,7 @@ pub(crate) fn match_arm_list(p: &mut Parser) { | |||
// | X => (), | |||
// box X => (), | |||
// Some(box X) => (), | |||
// Some(box Test{field: 0}) => (), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, actually, I think these last three lines are misplaced. I specifically looked for this in the previous PR and somehow still missed it =/
The purpose of these inline tests is to show what exactly each specific bit of code parses. box patterns are not handled in this function.
I see that you've added tests to fn box_pat
, where they belong, so these last three lines should be removed.
Some(m) | ||
} | ||
|
||
fn is_literal_pat_start(p: &mut Parser) -> bool { | ||
fn is_literal_pat_start(p: &Parser) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
// j: Box<Inner<'a>>, | ||
// } | ||
// | ||
// struct Inner<'a>(&'a i32); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove struct Ounter
and struct Inner
, they are completely irrelvent for testing syntax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it seems that this test only passes if there's something named Inner
and Outer
in scope. This is probably a shortcoming of the parsing code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't be the case. Judging by the actual .rs file in the inline
folder, looks like the test harness is confused over a blank line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get the following error if the names aren't in scope. It's an error in my parsing code, not sure why it went away when I changed the test, maybe the blank line?
thread 'tests::parser_tests' panicked at 'assertion failed: `(left == right)`
left: `[SyntaxError { kind: ParseError(ParseError("expected a name")), location: 52 }, SyntaxError { kind: ParseError(ParseError("expected COMMA")), location: 55 }]`,
right: `[]`: There should be no errors in the file "/home/mackendy/src/rust/rust-analyzer/crates/ra_syntax/test_data/parser/inline/ok/0143_box_pat.rs"', crates/ra_syntax/src/tests.rs:23:9
0143_box_pat.rs:
fn main() {
let box i = ();
let box Outer { box i, j: box Inner(box &x) } = ();
let box ref mut i = ();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed to extend record_field_pat_list
to handle the box i
part. This syntax is equivalent to i: box i
. I was a little surprised that it is in fact valid.
19d5c9e
to
75192f7
Compare
@matklad. Okay, this should be good to go now. Do you want me to rebase to clean up the latest changes or does bors squash automatically? |
bors doesn't squash, so a rebase wouldn't harm (though I personally don't value clean git history that much for small PR). |
Named structs can have `box` patterns that will bind to their fields. This is similar to the behavior of the `ref` and `mut` fields, but is at least a little bit surprising.
da0b860
to
c93903e
Compare
@matklad I cleaned it up. It's ready to merge if you want to give it one last look. |
bors r+ Thanks! |
1733: Parse arbitrarily complex `box` patterns. r=matklad a=ecstatic-morse This fully resolves the pattern part of #1412 by enabling the parsing of complex `box` patterns such as: ```rust let box Struct { box i, j: box Inner(box &x) } = todo!(); ``` This introduces a new `ast::BoxPat` (in the mold of `ast::RefPat`) that gets translated to `hir::Pat::Missing`. Co-authored-by: Dylan MacKenzie <ecstaticmorse@gmail.com>
Build succeeded |
This fully resolves the pattern part of #1412 by enabling the parsing of complex
box
patterns such as:This introduces a new
ast::BoxPat
(in the mold ofast::RefPat
) that gets translated tohir::Pat::Missing
.