Skip to content

Commit c246ecf

Browse files
committed
Auto merge of rust-lang#16310 - Veykril:range-access-parse, r=Veykril
fix: Fix incorrect parsing error on method call on range Fixes rust-lang/rust-analyzer#16289
2 parents 25f7146 + 7220064 commit c246ecf

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

crates/parser/src/grammar/expressions.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,15 @@ fn lhs(p: &mut Parser<'_>, r: Restrictions) -> Option<(CompletedMarker, BlockLik
371371
if p.at(op) {
372372
m = p.start();
373373
p.bump(op);
374-
if p.at_ts(EXPR_FIRST) && !(r.forbid_structs && p.at(T!['{'])) {
374+
375+
// test closure_range_method_call
376+
// fn foo() {
377+
// || .. .method();
378+
// || .. .field;
379+
// }
380+
let has_access_after = p.at(T![.]) && p.nth_at(1, SyntaxKind::IDENT);
381+
let struct_forbidden = r.forbid_structs && p.at(T!['{']);
382+
if p.at_ts(EXPR_FIRST) && !has_access_after && !struct_forbidden {
375383
expr_bp(p, None, r, 2);
376384
}
377385
let cm = m.complete(p, RANGE_EXPR);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
SOURCE_FILE
2+
FN
3+
FN_KW "fn"
4+
WHITESPACE " "
5+
NAME
6+
IDENT "foo"
7+
PARAM_LIST
8+
L_PAREN "("
9+
R_PAREN ")"
10+
WHITESPACE " "
11+
BLOCK_EXPR
12+
STMT_LIST
13+
L_CURLY "{"
14+
WHITESPACE "\n "
15+
EXPR_STMT
16+
METHOD_CALL_EXPR
17+
CLOSURE_EXPR
18+
PARAM_LIST
19+
PIPE "|"
20+
PIPE "|"
21+
WHITESPACE " "
22+
RANGE_EXPR
23+
DOT2 ".."
24+
WHITESPACE " "
25+
DOT "."
26+
NAME_REF
27+
IDENT "method"
28+
ARG_LIST
29+
L_PAREN "("
30+
R_PAREN ")"
31+
SEMICOLON ";"
32+
WHITESPACE "\n "
33+
EXPR_STMT
34+
FIELD_EXPR
35+
CLOSURE_EXPR
36+
PARAM_LIST
37+
PIPE "|"
38+
PIPE "|"
39+
WHITESPACE " "
40+
RANGE_EXPR
41+
DOT2 ".."
42+
WHITESPACE " "
43+
DOT "."
44+
NAME_REF
45+
IDENT "field"
46+
SEMICOLON ";"
47+
WHITESPACE "\n"
48+
R_CURLY "}"
49+
WHITESPACE "\n"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn foo() {
2+
|| .. .method();
3+
|| .. .field;
4+
}

0 commit comments

Comments
 (0)