aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-10-08 09:44:26 +0100
committerGitHub <[email protected]>2019-10-08 09:44:26 +0100
commitd9338dfa98964c0dac8fc082c3d9201807feced0 (patch)
tree2e1f841be60665df9e5c61845fb49e93a6332c68 /crates/ra_parser
parent523d7d2c8210b382146c76927e93f1cc8a6d31e2 (diff)
parentb4fe06bc17127b6007114a8ba8bf876fdef112e0 (diff)
Merge #1951
1951: Lower the precedence of the `as` operator. r=matklad a=goffrie Previously, the `as` operator was being parsed like a postfix expression, and therefore being given the highest possible precedence. That caused it to bind more tightly than prefix operators, which it should not. Instead, parse it somewhat like a normal binary expression with some special-casing. Fixes #1851. Co-authored-by: Geoffry Song <[email protected]>
Diffstat (limited to 'crates/ra_parser')
-rw-r--r--crates/ra_parser/src/grammar/expressions.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs
index 74b23e2f7..45f2e3de4 100644
--- a/crates/ra_parser/src/grammar/expressions.rs
+++ b/crates/ra_parser/src/grammar/expressions.rs
@@ -250,6 +250,7 @@ fn current_op(p: &Parser) -> (u8, SyntaxKind) {
250 T![!] if p.at(T![!=]) => (5, T![!=]), 250 T![!] if p.at(T![!=]) => (5, T![!=]),
251 T![-] if p.at(T![-=]) => (1, T![-=]), 251 T![-] if p.at(T![-=]) => (1, T![-=]),
252 T![-] => (10, T![-]), 252 T![-] => (10, T![-]),
253 T![as] => (12, T![as]),
253 254
254 _ => NOT_AN_OP 255 _ => NOT_AN_OP
255 } 256 }
@@ -278,6 +279,14 @@ fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> (Option<CompletedMarker>,
278 if op_bp < bp { 279 if op_bp < bp {
279 break; 280 break;
280 } 281 }
282 // test as_precedence
283 // fn foo() {
284 // let _ = &1 as *const i32;
285 // }
286 if p.at(T![as]) {
287 lhs = cast_expr(p, lhs);
288 continue;
289 }
281 let m = lhs.precede(p); 290 let m = lhs.precede(p);
282 p.bump(op); 291 p.bump(op);
283 292
@@ -344,6 +353,7 @@ fn lhs(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)>
344 )); 353 ));
345 } 354 }
346 }; 355 };
356 // parse the interior of the unary expression
347 expr_bp(p, r, 255); 357 expr_bp(p, r, 255);
348 Some((m.complete(p, kind), BlockLike::NotBlock)) 358 Some((m.complete(p, kind), BlockLike::NotBlock))
349} 359}
@@ -378,7 +388,6 @@ fn postfix_expr(
378 } 388 }
379 }, 389 },
380 T![?] => try_expr(p, lhs), 390 T![?] => try_expr(p, lhs),
381 T![as] => cast_expr(p, lhs),
382 _ => break, 391 _ => break,
383 }; 392 };
384 allow_calls = true; 393 allow_calls = true;