From 838820ad986e04dffa43fc2662a58da27d97db06 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 25 Aug 2018 13:21:43 +0300 Subject: fix assertione error on block parsing --- crates/libsyntax2/src/grammar/expressions/atom.rs | 6 +----- crates/libsyntax2/src/grammar/expressions/mod.rs | 5 ++++- crates/libsyntax2/src/grammar/items/mod.rs | 6 +++--- crates/libsyntax2/tests/data/parser/err/0015_curly_in_params.txt | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/crates/libsyntax2/src/grammar/expressions/atom.rs b/crates/libsyntax2/src/grammar/expressions/atom.rs index b0e270426..d9c3f998a 100644 --- a/crates/libsyntax2/src/grammar/expressions/atom.rs +++ b/crates/libsyntax2/src/grammar/expressions/atom.rs @@ -148,11 +148,7 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker { p.eat(MOVE_KW); params::param_list_opt_types(p); if opt_fn_ret_type(p) { - if p.at(L_CURLY) { - block(p); - } else { - p.error("expected a block"); - } + block(p); } else { expr(p); } diff --git a/crates/libsyntax2/src/grammar/expressions/mod.rs b/crates/libsyntax2/src/grammar/expressions/mod.rs index bd6c84886..922d9f871 100644 --- a/crates/libsyntax2/src/grammar/expressions/mod.rs +++ b/crates/libsyntax2/src/grammar/expressions/mod.rs @@ -26,7 +26,10 @@ fn expr_no_struct(p: &mut Parser) { // fn c() { 1; 2; } // fn d() { 1; 2 } 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(); p.bump(); while !p.at(EOF) && !p.at(R_CURLY) { diff --git a/crates/libsyntax2/src/grammar/items/mod.rs b/crates/libsyntax2/src/grammar/items/mod.rs index 44ab92c63..32d0778c4 100644 --- a/crates/libsyntax2/src/grammar/items/mod.rs +++ b/crates/libsyntax2/src/grammar/items/mod.rs @@ -252,10 +252,10 @@ fn function(p: &mut Parser, flavor: ItemFlavor) { // test fn_decl // trait T { fn foo(); } - if p.at(L_CURLY) { - expressions::block(p); + if p.at(SEMI) { + p.bump(); } else { - p.expect(SEMI); + expressions::block(p) } } diff --git a/crates/libsyntax2/tests/data/parser/err/0015_curly_in_params.txt b/crates/libsyntax2/tests/data/parser/err/0015_curly_in_params.txt index bd8356616..dbc19abea 100644 --- a/crates/libsyntax2/tests/data/parser/err/0015_curly_in_params.txt +++ b/crates/libsyntax2/tests/data/parser/err/0015_curly_in_params.txt @@ -8,7 +8,7 @@ ROOT@[0; 14) L_PAREN@[6; 7) err: `expected value parameter` err: `expected R_PAREN` - err: `expected SEMI` + err: `expected a block` err: `expected an item` ERROR@[7; 8) R_CURLY@[7; 8) -- cgit v1.2.3