Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #19897 from aibaars/patch-2
Produce ClosureBinder node in atom.rs
Lukas Wirth 11 months ago
parent 2a388d1 · parent 55328ba · commit b9e6671
-rw-r--r--crates/parser/src/grammar/expressions/atom.rs4
-rw-r--r--crates/parser/test_data/generated/runner.rs4
-rw-r--r--crates/parser/test_data/parser/err/0024_many_type_parens.rast15
-rw-r--r--crates/parser/test_data/parser/inline/ok/closure_binder.rast36
-rw-r--r--crates/parser/test_data/parser/inline/ok/closure_binder.rs1
-rw-r--r--crates/parser/test_data/parser/inline/ok/lambda_expr.rast30
6 files changed, 69 insertions, 21 deletions
diff --git a/crates/parser/src/grammar/expressions/atom.rs b/crates/parser/src/grammar/expressions/atom.rs
index 8cc332d463..8ed0fc6729 100644
--- a/crates/parser/src/grammar/expressions/atom.rs
+++ b/crates/parser/src/grammar/expressions/atom.rs
@@ -562,8 +562,12 @@ fn closure_expr(p: &mut Parser<'_>) -> CompletedMarker {
let m = p.start();
+ // test closure_binder
+ // fn main() { for<'a> || (); }
if p.at(T![for]) {
+ let b = p.start();
types::for_binder(p);
+ b.complete(p, CLOSURE_BINDER);
}
// test const_closure
// fn main() { let cl = const || _ = 0; }
diff --git a/crates/parser/test_data/generated/runner.rs b/crates/parser/test_data/generated/runner.rs
index 030d8e0f04..537f6df05b 100644
--- a/crates/parser/test_data/generated/runner.rs
+++ b/crates/parser/test_data/generated/runner.rs
@@ -83,6 +83,10 @@ mod ok {
#[test]
fn cast_expr() { run_and_expect_no_errors("test_data/parser/inline/ok/cast_expr.rs"); }
#[test]
+ fn closure_binder() {
+ run_and_expect_no_errors("test_data/parser/inline/ok/closure_binder.rs");
+ }
+ #[test]
fn closure_body_underscore_assignment() {
run_and_expect_no_errors(
"test_data/parser/inline/ok/closure_body_underscore_assignment.rs",
diff --git a/crates/parser/test_data/parser/err/0024_many_type_parens.rast b/crates/parser/test_data/parser/err/0024_many_type_parens.rast
index f0dbc9b102..025c12e4c2 100644
--- a/crates/parser/test_data/parser/err/0024_many_type_parens.rast
+++ b/crates/parser/test_data/parser/err/0024_many_type_parens.rast
@@ -186,13 +186,14 @@ SOURCE_FILE
TUPLE_EXPR
L_PAREN "("
CLOSURE_EXPR
- FOR_KW "for"
- GENERIC_PARAM_LIST
- L_ANGLE "<"
- LIFETIME_PARAM
- LIFETIME
- LIFETIME_IDENT "'a"
- R_ANGLE ">"
+ CLOSURE_BINDER
+ FOR_KW "for"
+ GENERIC_PARAM_LIST
+ L_ANGLE "<"
+ LIFETIME_PARAM
+ LIFETIME
+ LIFETIME_IDENT "'a"
+ R_ANGLE ">"
WHITESPACE " "
BIN_EXPR
BIN_EXPR
diff --git a/crates/parser/test_data/parser/inline/ok/closure_binder.rast b/crates/parser/test_data/parser/inline/ok/closure_binder.rast
new file mode 100644
index 0000000000..c04dbe1ea0
--- /dev/null
+++ b/crates/parser/test_data/parser/inline/ok/closure_binder.rast
@@ -0,0 +1,36 @@
+SOURCE_FILE
+ FN
+ FN_KW "fn"
+ WHITESPACE " "
+ NAME
+ IDENT "main"
+ PARAM_LIST
+ L_PAREN "("
+ R_PAREN ")"
+ WHITESPACE " "
+ BLOCK_EXPR
+ STMT_LIST
+ L_CURLY "{"
+ WHITESPACE " "
+ EXPR_STMT
+ CLOSURE_EXPR
+ CLOSURE_BINDER
+ FOR_KW "for"
+ GENERIC_PARAM_LIST
+ L_ANGLE "<"
+ LIFETIME_PARAM
+ LIFETIME
+ LIFETIME_IDENT "'a"
+ R_ANGLE ">"
+ WHITESPACE " "
+ PARAM_LIST
+ PIPE "|"
+ PIPE "|"
+ WHITESPACE " "
+ TUPLE_EXPR
+ L_PAREN "("
+ R_PAREN ")"
+ SEMICOLON ";"
+ WHITESPACE " "
+ R_CURLY "}"
+ WHITESPACE "\n"
diff --git a/crates/parser/test_data/parser/inline/ok/closure_binder.rs b/crates/parser/test_data/parser/inline/ok/closure_binder.rs
new file mode 100644
index 0000000000..a6d8aafb08
--- /dev/null
+++ b/crates/parser/test_data/parser/inline/ok/closure_binder.rs
@@ -0,0 +1 @@
+fn main() { for<'a> || (); }
diff --git a/crates/parser/test_data/parser/inline/ok/lambda_expr.rast b/crates/parser/test_data/parser/inline/ok/lambda_expr.rast
index c25ad8430d..ea401d224e 100644
--- a/crates/parser/test_data/parser/inline/ok/lambda_expr.rast
+++ b/crates/parser/test_data/parser/inline/ok/lambda_expr.rast
@@ -202,13 +202,14 @@ SOURCE_FILE
WHITESPACE "\n "
EXPR_STMT
CLOSURE_EXPR
- FOR_KW "for"
- GENERIC_PARAM_LIST
- L_ANGLE "<"
- LIFETIME_PARAM
- LIFETIME
- LIFETIME_IDENT "'a"
- R_ANGLE ">"
+ CLOSURE_BINDER
+ FOR_KW "for"
+ GENERIC_PARAM_LIST
+ L_ANGLE "<"
+ LIFETIME_PARAM
+ LIFETIME
+ LIFETIME_IDENT "'a"
+ R_ANGLE ">"
WHITESPACE " "
PARAM_LIST
PIPE "|"
@@ -222,13 +223,14 @@ SOURCE_FILE
WHITESPACE "\n "
EXPR_STMT
CLOSURE_EXPR
- FOR_KW "for"
- GENERIC_PARAM_LIST
- L_ANGLE "<"
- LIFETIME_PARAM
- LIFETIME
- LIFETIME_IDENT "'a"
- R_ANGLE ">"
+ CLOSURE_BINDER
+ FOR_KW "for"
+ GENERIC_PARAM_LIST
+ L_ANGLE "<"
+ LIFETIME_PARAM
+ LIFETIME
+ LIFETIME_IDENT "'a"
+ R_ANGLE ">"
WHITESPACE " "
MOVE_KW "move"
WHITESPACE " "