diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-01 11:57:06 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-01 11:57:06 +0100 |
commit | 6e4865de73aae64c9285dd0f3f89984a59c02c2e (patch) | |
tree | 5870b84becc89f88a554eef9a5762e2f38add050 /crates/ra_parser/src | |
parent | 42a883f06c28ddeab22e5703a578f19110dde7f3 (diff) | |
parent | d43dff43b4bb89306c418222df3b262a715c0fda (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/ra_parser/src')
-rw-r--r-- | crates/ra_parser/src/grammar/expressions/atom.rs | 14 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/items.rs | 2 |
2 files changed, 13 insertions, 3 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 | // } |
194 | fn lambda_expr(p: &mut Parser) -> CompletedMarker { | 198 | fn 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 | } |