mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 20:43:21 +00:00
Fix parsing lambdas with return type
We should eat only a single block, and not whatever larger expression may start with a block. closes #3721
This commit is contained in:
parent
785eb32f49
commit
f6188caaa0
4 changed files with 75 additions and 21 deletions
|
@ -230,15 +230,21 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker {
|
|||
p.eat(T![async]);
|
||||
p.eat(T![move]);
|
||||
params::param_list_closure(p);
|
||||
if opt_fn_ret_type(p) && !p.at(T!['{']) {
|
||||
if opt_fn_ret_type(p) {
|
||||
if p.at(T!['{']) {
|
||||
// test lambda_ret_block
|
||||
// fn main() { || -> i32 { 92 }(); }
|
||||
block_expr(p, None);
|
||||
} else {
|
||||
p.error("expected `{`");
|
||||
}
|
||||
|
||||
} else {
|
||||
if p.at_ts(EXPR_FIRST) {
|
||||
expr(p);
|
||||
} else {
|
||||
p.error("expected expression");
|
||||
}
|
||||
}
|
||||
m.complete(p, LAMBDA_EXPR)
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ SOURCE_FILE@[0; 42)
|
|||
BLOCK@[10; 41)
|
||||
L_CURLY@[10; 11) "{"
|
||||
WHITESPACE@[11; 16) "\n "
|
||||
EXPR_STMT@[16; 39)
|
||||
LAMBDA_EXPR@[16; 38)
|
||||
EXPR_STMT@[16; 24)
|
||||
LAMBDA_EXPR@[16; 24)
|
||||
PARAM_LIST@[16; 18)
|
||||
PIPE@[16; 17) "|"
|
||||
PIPE@[17; 18) "|"
|
||||
|
@ -25,6 +25,7 @@ SOURCE_FILE@[0; 42)
|
|||
L_PAREN@[22; 23) "("
|
||||
R_PAREN@[23; 24) ")"
|
||||
WHITESPACE@[24; 25) " "
|
||||
EXPR_STMT@[25; 39)
|
||||
BLOCK_EXPR@[25; 38)
|
||||
UNSAFE_KW@[25; 31) "unsafe"
|
||||
WHITESPACE@[31; 32) " "
|
||||
|
@ -41,3 +42,4 @@ SOURCE_FILE@[0; 42)
|
|||
R_CURLY@[40; 41) "}"
|
||||
WHITESPACE@[41; 42) "\n"
|
||||
error [24; 24): expected `{`
|
||||
error [24; 24): expected SEMI
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
fn main() { || -> i32 { 92 }(); }
|
|
@ -0,0 +1,45 @@
|
|||
SOURCE_FILE@[0; 34)
|
||||
FN_DEF@[0; 33)
|
||||
FN_KW@[0; 2) "fn"
|
||||
WHITESPACE@[2; 3) " "
|
||||
NAME@[3; 7)
|
||||
IDENT@[3; 7) "main"
|
||||
PARAM_LIST@[7; 9)
|
||||
L_PAREN@[7; 8) "("
|
||||
R_PAREN@[8; 9) ")"
|
||||
WHITESPACE@[9; 10) " "
|
||||
BLOCK_EXPR@[10; 33)
|
||||
BLOCK@[10; 33)
|
||||
L_CURLY@[10; 11) "{"
|
||||
WHITESPACE@[11; 12) " "
|
||||
EXPR_STMT@[12; 31)
|
||||
CALL_EXPR@[12; 30)
|
||||
LAMBDA_EXPR@[12; 28)
|
||||
PARAM_LIST@[12; 14)
|
||||
PIPE@[12; 13) "|"
|
||||
PIPE@[13; 14) "|"
|
||||
WHITESPACE@[14; 15) " "
|
||||
RET_TYPE@[15; 21)
|
||||
THIN_ARROW@[15; 17) "->"
|
||||
WHITESPACE@[17; 18) " "
|
||||
PATH_TYPE@[18; 21)
|
||||
PATH@[18; 21)
|
||||
PATH_SEGMENT@[18; 21)
|
||||
NAME_REF@[18; 21)
|
||||
IDENT@[18; 21) "i32"
|
||||
WHITESPACE@[21; 22) " "
|
||||
BLOCK_EXPR@[22; 28)
|
||||
BLOCK@[22; 28)
|
||||
L_CURLY@[22; 23) "{"
|
||||
WHITESPACE@[23; 24) " "
|
||||
LITERAL@[24; 26)
|
||||
INT_NUMBER@[24; 26) "92"
|
||||
WHITESPACE@[26; 27) " "
|
||||
R_CURLY@[27; 28) "}"
|
||||
ARG_LIST@[28; 30)
|
||||
L_PAREN@[28; 29) "("
|
||||
R_PAREN@[29; 30) ")"
|
||||
SEMI@[30; 31) ";"
|
||||
WHITESPACE@[31; 32) " "
|
||||
R_CURLY@[32; 33) "}"
|
||||
WHITESPACE@[33; 34) "\n"
|
Loading…
Reference in a new issue