diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-08-13 13:46:47 +0100 |
---|---|---|
committer | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-08-13 13:46:47 +0100 |
commit | 978e3e384b045ea72ba952e7f94a2a4c82297e66 (patch) | |
tree | 934770bc4dd73e3c829a67e13858bbd941b92f27 /crates/ra_parser | |
parent | 2c65a059840dd2092a00e90337a8221cd832c456 (diff) | |
parent | eb0e9bd98132dabbd908b473c5c1131f0787ffac (diff) |
Merge #1636
1636: fix block parse problem r=matklad a=bravomikekilo
try to fix [issue-1598](https://github.com/rust-analyzer/rust-analyzer/issues/1598).
Co-authored-by: bravomikekilo <[email protected]>
Diffstat (limited to 'crates/ra_parser')
-rw-r--r-- | crates/ra_parser/src/grammar/expressions.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index 9fd3a235d..742076c1a 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs | |||
@@ -359,11 +359,14 @@ fn lhs( | |||
359 | return Some((m.complete(p, RANGE_EXPR), BlockLike::NotBlock)); | 359 | return Some((m.complete(p, RANGE_EXPR), BlockLike::NotBlock)); |
360 | } | 360 | } |
361 | _ => { | 361 | _ => { |
362 | // test expression_after_block | ||
363 | // fn foo() { | ||
364 | // let mut p = F{x: 5}; | ||
365 | // {p}.x = 10; | ||
366 | // } | ||
367 | // | ||
362 | let (lhs, blocklike) = atom::atom_expr(p, r)?; | 368 | let (lhs, blocklike) = atom::atom_expr(p, r)?; |
363 | return Some(( | 369 | return Some(postfix_expr(p, lhs, blocklike, !(r.prefer_stmt && blocklike.is_block()))); |
364 | postfix_expr(p, lhs, !(r.prefer_stmt && blocklike.is_block())), | ||
365 | blocklike, | ||
366 | )); | ||
367 | } | 370 | } |
368 | }; | 371 | }; |
369 | expr_bp(p, r, 255, dollar_lvl); | 372 | expr_bp(p, r, 255, dollar_lvl); |
@@ -376,8 +379,9 @@ fn postfix_expr( | |||
376 | // Calls are disallowed if the type is a block and we prefer statements because the call cannot be disambiguated from a tuple | 379 | // Calls are disallowed if the type is a block and we prefer statements because the call cannot be disambiguated from a tuple |
377 | // E.g. `while true {break}();` is parsed as | 380 | // E.g. `while true {break}();` is parsed as |
378 | // `while true {break}; ();` | 381 | // `while true {break}; ();` |
382 | mut block_like: BlockLike, | ||
379 | mut allow_calls: bool, | 383 | mut allow_calls: bool, |
380 | ) -> CompletedMarker { | 384 | ) -> (CompletedMarker, BlockLike) { |
381 | loop { | 385 | loop { |
382 | lhs = match p.current() { | 386 | lhs = match p.current() { |
383 | // test stmt_postfix_expr_ambiguity | 387 | // test stmt_postfix_expr_ambiguity |
@@ -417,9 +421,10 @@ fn postfix_expr( | |||
417 | T![as] => cast_expr(p, lhs), | 421 | T![as] => cast_expr(p, lhs), |
418 | _ => break, | 422 | _ => break, |
419 | }; | 423 | }; |
420 | allow_calls = true | 424 | allow_calls = true; |
425 | block_like = BlockLike::NotBlock; | ||
421 | } | 426 | } |
422 | lhs | 427 | (lhs, block_like) |
423 | } | 428 | } |
424 | 429 | ||
425 | // test call_expr | 430 | // test call_expr |