aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_parser/src/grammar/expressions.rs10
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0158_binop_resets_statementness.rs3
-rw-r--r--crates/ra_syntax/test_data/parser/inline/ok/0158_binop_resets_statementness.txt38
3 files changed, 49 insertions, 2 deletions
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs
index 4163a2cf5..0c170ac5e 100644
--- a/crates/ra_parser/src/grammar/expressions.rs
+++ b/crates/ra_parser/src/grammar/expressions.rs
@@ -278,7 +278,7 @@ fn current_op(p: &Parser) -> (u8, SyntaxKind) {
278} 278}
279 279
280// Parses expression with binding power of at least bp. 280// Parses expression with binding power of at least bp.
281fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> (Option<CompletedMarker>, BlockLike) { 281fn expr_bp(p: &mut Parser, mut r: Restrictions, bp: u8) -> (Option<CompletedMarker>, BlockLike) {
282 let mut lhs = match lhs(p, r) { 282 let mut lhs = match lhs(p, r) {
283 Some((lhs, blocklike)) => { 283 Some((lhs, blocklike)) => {
284 // test stmt_bin_expr_ambiguity 284 // test stmt_bin_expr_ambiguity
@@ -311,6 +311,12 @@ fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> (Option<CompletedMarker>,
311 let m = lhs.precede(p); 311 let m = lhs.precede(p);
312 p.bump(op); 312 p.bump(op);
313 313
314 // test binop_resets_statementness
315 // fn foo() {
316 // v = {1}&2;
317 // }
318 r = Restrictions { prefer_stmt: false, ..r };
319
314 if is_range { 320 if is_range {
315 // test postfix_range 321 // test postfix_range
316 // fn foo() { 322 // fn foo() {
@@ -327,7 +333,7 @@ fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> (Option<CompletedMarker>,
327 } 333 }
328 } 334 }
329 335
330 expr_bp(p, r, op_bp + 1); 336 expr_bp(p, Restrictions { prefer_stmt: false, ..r }, op_bp + 1);
331 lhs = m.complete(p, if is_range { RANGE_EXPR } else { BIN_EXPR }); 337 lhs = m.complete(p, if is_range { RANGE_EXPR } else { BIN_EXPR });
332 } 338 }
333 (Some(lhs), BlockLike::NotBlock) 339 (Some(lhs), BlockLike::NotBlock)
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0158_binop_resets_statementness.rs b/crates/ra_syntax/test_data/parser/inline/ok/0158_binop_resets_statementness.rs
new file mode 100644
index 000000000..05acc30f1
--- /dev/null
+++ b/crates/ra_syntax/test_data/parser/inline/ok/0158_binop_resets_statementness.rs
@@ -0,0 +1,3 @@
1fn foo() {
2 v = {1}&2;
3}
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0158_binop_resets_statementness.txt b/crates/ra_syntax/test_data/parser/inline/ok/0158_binop_resets_statementness.txt
new file mode 100644
index 000000000..d568a1d45
--- /dev/null
+++ b/crates/ra_syntax/test_data/parser/inline/ok/0158_binop_resets_statementness.txt
@@ -0,0 +1,38 @@
1SOURCE_FILE@[0; 28)
2 FN_DEF@[0; 27)
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_EXPR@[9; 27)
12 BLOCK@[9; 27)
13 L_CURLY@[9; 10) "{"
14 WHITESPACE@[10; 15) "\n "
15 EXPR_STMT@[15; 25)
16 BIN_EXPR@[15; 24)
17 PATH_EXPR@[15; 16)
18 PATH@[15; 16)
19 PATH_SEGMENT@[15; 16)
20 NAME_REF@[15; 16)
21 IDENT@[15; 16) "v"
22 WHITESPACE@[16; 17) " "
23 EQ@[17; 18) "="
24 WHITESPACE@[18; 19) " "
25 BIN_EXPR@[19; 24)
26 BLOCK_EXPR@[19; 22)
27 BLOCK@[19; 22)
28 L_CURLY@[19; 20) "{"
29 LITERAL@[20; 21)
30 INT_NUMBER@[20; 21) "1"
31 R_CURLY@[21; 22) "}"
32 AMP@[22; 23) "&"
33 LITERAL@[23; 24)
34 INT_NUMBER@[23; 24) "2"
35 SEMI@[24; 25) ";"
36 WHITESPACE@[25; 26) "\n"
37 R_CURLY@[26; 27) "}"
38 WHITESPACE@[27; 28) "\n"