aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_parser/src/grammar/expressions.rs19
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0138_expression_after_block.rs4
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0138_expression_after_block.txt65
3 files changed, 81 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
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0138_expression_after_block.rs b/crates/ra_syntax/test_data/parser/inline/ok/0138_expression_after_block.rs
new file mode 100644
index 000000000..76007e3ee
--- /dev/null
+++ b/crates/ra_syntax/test_data/parser/inline/ok/0138_expression_after_block.rs
@@ -0,0 +1,4 @@
1fn foo() {
2 let mut p = F{x: 5};
3 {p}.x = 10;
4}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0138_expression_after_block.txt b/crates/ra_syntax/test_data/parser/inline/ok/0138_expression_after_block.txt
new file mode 100644
index 000000000..08128f365
--- /dev/null
+++ b/crates/ra_syntax/test_data/parser/inline/ok/0138_expression_after_block.txt
@@ -0,0 +1,65 @@
1SOURCE_FILE@[0; 52)
2 FN_DEF@[0; 51)
3 FN_KW@[0; 2) "fn"
4 WHITESPACE@[2; 3) " "
5 NAME@[3; 6)
6 IDENT@[3; 6) "foo"
7 PARAM_LIST@[6; 8)
8 L_PAREN@[6; 7) "("
9 R_PAREN@[7; 8) ")"
10 WHITESPACE@[8; 9) " "
11 BLOCK@[9; 51)
12 L_CURLY@[9; 10) "{"
13 WHITESPACE@[10; 14) "\n "
14 LET_STMT@[14; 34)
15 LET_KW@[14; 17) "let"
16 WHITESPACE@[17; 18) " "
17 BIND_PAT@[18; 23)
18 MUT_KW@[18; 21) "mut"
19 WHITESPACE@[21; 22) " "
20 NAME@[22; 23)
21 IDENT@[22; 23) "p"
22 WHITESPACE@[23; 24) " "
23 EQ@[24; 25) "="
24 WHITESPACE@[25; 26) " "
25 STRUCT_LIT@[26; 33)
26 PATH@[26; 27)
27 PATH_SEGMENT@[26; 27)
28 NAME_REF@[26; 27)
29 IDENT@[26; 27) "F"
30 NAMED_FIELD_LIST@[27; 33)
31 L_CURLY@[27; 28) "{"
32 NAMED_FIELD@[28; 32)
33 NAME_REF@[28; 29)
34 IDENT@[28; 29) "x"
35 COLON@[29; 30) ":"
36 WHITESPACE@[30; 31) " "
37 LITERAL@[31; 32)
38 INT_NUMBER@[31; 32) "5"
39 R_CURLY@[32; 33) "}"
40 SEMI@[33; 34) ";"
41 WHITESPACE@[34; 38) "\n "
42 EXPR_STMT@[38; 49)
43 BIN_EXPR@[38; 48)
44 FIELD_EXPR@[38; 43)
45 BLOCK_EXPR@[38; 41)
46 BLOCK@[38; 41)
47 L_CURLY@[38; 39) "{"
48 PATH_EXPR@[39; 40)
49 PATH@[39; 40)
50 PATH_SEGMENT@[39; 40)
51 NAME_REF@[39; 40)
52 IDENT@[39; 40) "p"
53 R_CURLY@[40; 41) "}"
54 DOT@[41; 42) "."
55 NAME_REF@[42; 43)
56 IDENT@[42; 43) "x"
57 WHITESPACE@[43; 44) " "
58 EQ@[44; 45) "="
59 WHITESPACE@[45; 46) " "
60 LITERAL@[46; 48)
61 INT_NUMBER@[46; 48) "10"
62 SEMI@[48; 49) ";"
63 WHITESPACE@[49; 50) "\n"
64 R_CURLY@[50; 51) "}"
65 WHITESPACE@[51; 52) "\n"