fix assertione error on block parsing

This commit is contained in:
Aleksey Kladov 2018-08-25 13:21:43 +03:00
parent fed5727ea2
commit 838820ad98
4 changed files with 9 additions and 10 deletions

View file

@ -148,11 +148,7 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker {
p.eat(MOVE_KW); p.eat(MOVE_KW);
params::param_list_opt_types(p); params::param_list_opt_types(p);
if opt_fn_ret_type(p) { if opt_fn_ret_type(p) {
if p.at(L_CURLY) { block(p);
block(p);
} else {
p.error("expected a block");
}
} else { } else {
expr(p); expr(p);
} }

View file

@ -26,7 +26,10 @@ fn expr_no_struct(p: &mut Parser) {
// fn c() { 1; 2; } // fn c() { 1; 2; }
// fn d() { 1; 2 } // fn d() { 1; 2 }
pub(crate) fn block(p: &mut Parser) { pub(crate) fn block(p: &mut Parser) {
assert!(p.at(L_CURLY)); if !p.at(L_CURLY) {
p.error("expected a block");
return;
}
let m = p.start(); let m = p.start();
p.bump(); p.bump();
while !p.at(EOF) && !p.at(R_CURLY) { while !p.at(EOF) && !p.at(R_CURLY) {

View file

@ -252,10 +252,10 @@ fn function(p: &mut Parser, flavor: ItemFlavor) {
// test fn_decl // test fn_decl
// trait T { fn foo(); } // trait T { fn foo(); }
if p.at(L_CURLY) { if p.at(SEMI) {
expressions::block(p); p.bump();
} else { } else {
p.expect(SEMI); expressions::block(p)
} }
} }

View file

@ -8,7 +8,7 @@ ROOT@[0; 14)
L_PAREN@[6; 7) L_PAREN@[6; 7)
err: `expected value parameter` err: `expected value parameter`
err: `expected R_PAREN` err: `expected R_PAREN`
err: `expected SEMI` err: `expected a block`
err: `expected an item` err: `expected an item`
ERROR@[7; 8) ERROR@[7; 8)
R_CURLY@[7; 8) R_CURLY@[7; 8)