aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-01 11:57:06 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-01 11:57:06 +0100
commit6e4865de73aae64c9285dd0f3f89984a59c02c2e (patch)
tree5870b84becc89f88a554eef9a5762e2f38add050 /crates
parent42a883f06c28ddeab22e5703a578f19110dde7f3 (diff)
parentd43dff43b4bb89306c418222df3b262a715c0fda (diff)
Merge #1081
1081: Async closure syntax r=matklad a=robojumper Fixes #1080. Also fixes an error introduced by #1072 where something like `async move "foo"` in expression position would trigger the assertion in `block_expr`. Co-authored-by: robojumper <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs14
-rw-r--r--crates/ra_parser/src/grammar/items.rs2
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0106_lambda_expr.rs3
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0106_lambda_expr.txt56
4 files changed, 66 insertions, 9 deletions
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs
index 8653d4055..d0feed616 100644
--- a/crates/ra_parser/src/grammar/expressions/atom.rs
+++ b/crates/ra_parser/src/grammar/expressions/atom.rs
@@ -68,6 +68,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
68 L_BRACK => array_expr(p), 68 L_BRACK => array_expr(p),
69 PIPE => lambda_expr(p), 69 PIPE => lambda_expr(p),
70 MOVE_KW if la == PIPE => lambda_expr(p), 70 MOVE_KW if la == PIPE => lambda_expr(p),
71 ASYNC_KW if la == PIPE || (la == MOVE_KW && p.nth(2) == PIPE) => lambda_expr(p),
71 IF_KW => if_expr(p), 72 IF_KW => if_expr(p),
72 73
73 LOOP_KW => loop_expr(p, None), 74 LOOP_KW => loop_expr(p, None),
@@ -92,7 +93,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
92 } 93 }
93 } 94 }
94 } 95 }
95 ASYNC_KW if la == L_CURLY || la == MOVE_KW => { 96 ASYNC_KW if la == L_CURLY || (la == MOVE_KW && p.nth(2) == L_CURLY) => {
96 let m = p.start(); 97 let m = p.start();
97 p.bump(); 98 p.bump();
98 p.eat(MOVE_KW); 99 p.eat(MOVE_KW);
@@ -190,10 +191,19 @@ fn array_expr(p: &mut Parser) -> CompletedMarker {
190// || -> i32 { 92 }; 191// || -> i32 { 92 };
191// |x| x; 192// |x| x;
192// move |x: i32,| x; 193// move |x: i32,| x;
194// async || {};
195// move || {};
196// async move || {};
193// } 197// }
194fn lambda_expr(p: &mut Parser) -> CompletedMarker { 198fn lambda_expr(p: &mut Parser) -> CompletedMarker {
195 assert!(p.at(PIPE) || (p.at(MOVE_KW) && p.nth(1) == PIPE)); 199 assert!(
200 p.at(PIPE)
201 || (p.at(MOVE_KW) && p.nth(1) == PIPE)
202 || (p.at(ASYNC_KW) && p.nth(1) == PIPE)
203 || (p.at(ASYNC_KW) && p.nth(1) == MOVE_KW && p.nth(2) == PIPE)
204 );
196 let m = p.start(); 205 let m = p.start();
206 p.eat(ASYNC_KW);
197 p.eat(MOVE_KW); 207 p.eat(MOVE_KW);
198 params::param_list_opt_types(p); 208 params::param_list_opt_types(p);
199 if opt_fn_ret_type(p) { 209 if opt_fn_ret_type(p) {
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs
index 8d8828652..c4b8ef3c7 100644
--- a/crates/ra_parser/src/grammar/items.rs
+++ b/crates/ra_parser/src/grammar/items.rs
@@ -82,7 +82,7 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
82 // test_err async_without_semicolon 82 // test_err async_without_semicolon
83 // fn foo() { let _ = async {} } 83 // fn foo() { let _ = async {} }
84 has_mods |= p.eat(CONST_KW); 84 has_mods |= p.eat(CONST_KW);
85 if p.at(ASYNC_KW) && p.nth(1) != L_CURLY && p.nth(1) != MOVE_KW { 85 if p.at(ASYNC_KW) && p.nth(1) != L_CURLY && p.nth(1) != MOVE_KW && p.nth(1) != PIPE {
86 p.eat(ASYNC_KW); 86 p.eat(ASYNC_KW);
87 has_mods = true; 87 has_mods = true;
88 } 88 }
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0106_lambda_expr.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0106_lambda_expr.rs
index c20d29751..075717823 100644
--- a/crates/ra_syntax/tests/data/parser/inline/ok/0106_lambda_expr.rs
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0106_lambda_expr.rs
@@ -3,4 +3,7 @@ fn foo() {
3 || -> i32 { 92 }; 3 || -> i32 { 92 };
4 |x| x; 4 |x| x;
5 move |x: i32,| x; 5 move |x: i32,| x;
6 async || {};
7 move || {};
8 async move || {};
6} 9}
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0106_lambda_expr.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0106_lambda_expr.txt
index 98271c233..b885d239a 100644
--- a/crates/ra_syntax/tests/data/parser/inline/ok/0106_lambda_expr.txt
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0106_lambda_expr.txt
@@ -1,5 +1,5 @@
1SOURCE_FILE@[0; 79) 1SOURCE_FILE@[0; 134)
2 FN_DEF@[0; 78) 2 FN_DEF@[0; 133)
3 FN_KW@[0; 2) 3 FN_KW@[0; 2)
4 WHITESPACE@[2; 3) 4 WHITESPACE@[2; 3)
5 NAME@[3; 6) 5 NAME@[3; 6)
@@ -8,7 +8,7 @@ SOURCE_FILE@[0; 79)
8 L_PAREN@[6; 7) 8 L_PAREN@[6; 7)
9 R_PAREN@[7; 8) 9 R_PAREN@[7; 8)
10 WHITESPACE@[8; 9) 10 WHITESPACE@[8; 9)
11 BLOCK@[9; 78) 11 BLOCK@[9; 133)
12 L_CURLY@[9; 10) 12 L_CURLY@[9; 10)
13 WHITESPACE@[10; 15) 13 WHITESPACE@[10; 15)
14 EXPR_STMT@[15; 21) 14 EXPR_STMT@[15; 21)
@@ -90,6 +90,50 @@ SOURCE_FILE@[0; 79)
90 NAME_REF@[74; 75) 90 NAME_REF@[74; 75)
91 IDENT@[74; 75) "x" 91 IDENT@[74; 75) "x"
92 SEMI@[75; 76) 92 SEMI@[75; 76)
93 WHITESPACE@[76; 77) 93 WHITESPACE@[76; 81)
94 R_CURLY@[77; 78) 94 EXPR_STMT@[81; 93)
95 WHITESPACE@[78; 79) 95 LAMBDA_EXPR@[81; 92)
96 ASYNC_KW@[81; 86)
97 WHITESPACE@[86; 87)
98 PARAM_LIST@[87; 89)
99 PIPE@[87; 88)
100 PIPE@[88; 89)
101 WHITESPACE@[89; 90)
102 BLOCK_EXPR@[90; 92)
103 BLOCK@[90; 92)
104 L_CURLY@[90; 91)
105 R_CURLY@[91; 92)
106 SEMI@[92; 93)
107 WHITESPACE@[93; 98)
108 EXPR_STMT@[98; 109)
109 LAMBDA_EXPR@[98; 108)
110 MOVE_KW@[98; 102)
111 WHITESPACE@[102; 103)
112 PARAM_LIST@[103; 105)
113 PIPE@[103; 104)
114 PIPE@[104; 105)
115 WHITESPACE@[105; 106)
116 BLOCK_EXPR@[106; 108)
117 BLOCK@[106; 108)
118 L_CURLY@[106; 107)
119 R_CURLY@[107; 108)
120 SEMI@[108; 109)
121 WHITESPACE@[109; 114)
122 EXPR_STMT@[114; 131)
123 LAMBDA_EXPR@[114; 130)
124 ASYNC_KW@[114; 119)
125 WHITESPACE@[119; 120)
126 MOVE_KW@[120; 124)
127 WHITESPACE@[124; 125)
128 PARAM_LIST@[125; 127)
129 PIPE@[125; 126)
130 PIPE@[126; 127)
131 WHITESPACE@[127; 128)
132 BLOCK_EXPR@[128; 130)
133 BLOCK@[128; 130)
134 L_CURLY@[128; 129)
135 R_CURLY@[129; 130)
136 SEMI@[130; 131)
137 WHITESPACE@[131; 132)
138 R_CURLY@[132; 133)
139 WHITESPACE@[133; 134)