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:
Aleksey Kladov 2020-03-25 16:41:50 +01:00
parent 785eb32f49
commit f6188caaa0
4 changed files with 75 additions and 21 deletions

View file

@ -230,14 +230,20 @@ 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!['{']) {
p.error("expected `{`");
}
if p.at_ts(EXPR_FIRST) {
expr(p);
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 {
p.error("expected expression");
if p.at_ts(EXPR_FIRST) {
expr(p);
} else {
p.error("expected expression");
}
}
m.complete(p, LAMBDA_EXPR)
}