aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-25 11:21:43 +0100
committerAleksey Kladov <[email protected]>2018-08-25 11:21:43 +0100
commit838820ad986e04dffa43fc2662a58da27d97db06 (patch)
tree4bd77e98865c781d73a2beec795e42acbcd8ba0f /crates/libsyntax2
parentfed5727ea2669712e5d85502767b5c150203ecfc (diff)
fix assertione error on block parsing
Diffstat (limited to 'crates/libsyntax2')
-rw-r--r--crates/libsyntax2/src/grammar/expressions/atom.rs6
-rw-r--r--crates/libsyntax2/src/grammar/expressions/mod.rs5
-rw-r--r--crates/libsyntax2/src/grammar/items/mod.rs6
-rw-r--r--crates/libsyntax2/tests/data/parser/err/0015_curly_in_params.txt2
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 {
148 p.eat(MOVE_KW); 148 p.eat(MOVE_KW);
149 params::param_list_opt_types(p); 149 params::param_list_opt_types(p);
150 if opt_fn_ret_type(p) { 150 if opt_fn_ret_type(p) {
151 if p.at(L_CURLY) { 151 block(p);
152 block(p);
153 } else {
154 p.error("expected a block");
155 }
156 } else { 152 } else {
157 expr(p); 153 expr(p);
158 } 154 }
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) {
26// fn c() { 1; 2; } 26// fn c() { 1; 2; }
27// fn d() { 1; 2 } 27// fn d() { 1; 2 }
28pub(crate) fn block(p: &mut Parser) { 28pub(crate) fn block(p: &mut Parser) {
29 assert!(p.at(L_CURLY)); 29 if !p.at(L_CURLY) {
30 p.error("expected a block");
31 return;
32 }
30 let m = p.start(); 33 let m = p.start();
31 p.bump(); 34 p.bump();
32 while !p.at(EOF) && !p.at(R_CURLY) { 35 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) {
252 252
253 // test fn_decl 253 // test fn_decl
254 // trait T { fn foo(); } 254 // trait T { fn foo(); }
255 if p.at(L_CURLY) { 255 if p.at(SEMI) {
256 expressions::block(p); 256 p.bump();
257 } else { 257 } else {
258 p.expect(SEMI); 258 expressions::block(p)
259 } 259 }
260} 260}
261 261
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)
8 L_PAREN@[6; 7) 8 L_PAREN@[6; 7)
9 err: `expected value parameter` 9 err: `expected value parameter`
10 err: `expected R_PAREN` 10 err: `expected R_PAREN`
11 err: `expected SEMI` 11 err: `expected a block`
12 err: `expected an item` 12 err: `expected an item`
13 ERROR@[7; 8) 13 ERROR@[7; 8)
14 R_CURLY@[7; 8) 14 R_CURLY@[7; 8)