From 367e523442520a1ff9050210ee2573ac1abe4b25 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 25 Aug 2018 16:04:47 +0300 Subject: [PATCH] Require semi after exprs --- .../libsyntax2/src/grammar/expressions/mod.rs | 11 +++-- .../parser/err/0010_unsafe_lambda_block.txt | 24 ++++++----- .../data/parser/err/0016_missing_semi.rs | 6 +++ .../data/parser/err/0016_missing_semi.txt | 43 +++++++++++++++++++ 4 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 crates/libsyntax2/tests/data/parser/err/0016_missing_semi.rs create mode 100644 crates/libsyntax2/tests/data/parser/err/0016_missing_semi.txt diff --git a/crates/libsyntax2/src/grammar/expressions/mod.rs b/crates/libsyntax2/src/grammar/expressions/mod.rs index 922d9f8710..fb702a3987 100644 --- a/crates/libsyntax2/src/grammar/expressions/mod.rs +++ b/crates/libsyntax2/src/grammar/expressions/mod.rs @@ -51,10 +51,15 @@ pub(crate) fn block(p: &mut Parser) { // fn foo() { pub 92; } //FIXME items::MaybeItem::None => { let is_blocklike = expressions::expr_stmt(p) == BlockLike::Block; - if p.eat(SEMI) || (is_blocklike && !p.at(R_CURLY)) { - m.complete(p, EXPR_STMT); - } else { + if p.at(R_CURLY) { m.abandon(p); + } else { + if is_blocklike { + p.eat(SEMI); + } else { + p.expect(SEMI); + } + m.complete(p, EXPR_STMT); } } } diff --git a/crates/libsyntax2/tests/data/parser/err/0010_unsafe_lambda_block.txt b/crates/libsyntax2/tests/data/parser/err/0010_unsafe_lambda_block.txt index 6cda8543f5..400442c515 100644 --- a/crates/libsyntax2/tests/data/parser/err/0010_unsafe_lambda_block.txt +++ b/crates/libsyntax2/tests/data/parser/err/0010_unsafe_lambda_block.txt @@ -11,17 +11,19 @@ ROOT@[0; 42) BLOCK@[10; 41) L_CURLY@[10; 11) WHITESPACE@[11; 16) - LAMBDA_EXPR@[16; 24) - PARAM_LIST@[16; 18) - PIPE@[16; 17) - PIPE@[17; 18) - WHITESPACE@[18; 19) - THIN_ARROW@[19; 21) - WHITESPACE@[21; 22) - TUPLE_TYPE@[22; 24) - L_PAREN@[22; 23) - R_PAREN@[23; 24) - err: `expected a block` + EXPR_STMT@[16; 24) + LAMBDA_EXPR@[16; 24) + PARAM_LIST@[16; 18) + PIPE@[16; 17) + PIPE@[17; 18) + WHITESPACE@[18; 19) + THIN_ARROW@[19; 21) + WHITESPACE@[21; 22) + TUPLE_TYPE@[22; 24) + L_PAREN@[22; 23) + R_PAREN@[23; 24) + err: `expected a block` + err: `expected SEMI` WHITESPACE@[24; 25) EXPR_STMT@[25; 39) BLOCK_EXPR@[25; 38) diff --git a/crates/libsyntax2/tests/data/parser/err/0016_missing_semi.rs b/crates/libsyntax2/tests/data/parser/err/0016_missing_semi.rs new file mode 100644 index 0000000000..9ae8576861 --- /dev/null +++ b/crates/libsyntax2/tests/data/parser/err/0016_missing_semi.rs @@ -0,0 +1,6 @@ +fn foo() { + foo( + 1, 2 + ) + return 92; +} diff --git a/crates/libsyntax2/tests/data/parser/err/0016_missing_semi.txt b/crates/libsyntax2/tests/data/parser/err/0016_missing_semi.txt new file mode 100644 index 0000000000..a3163adcbf --- /dev/null +++ b/crates/libsyntax2/tests/data/parser/err/0016_missing_semi.txt @@ -0,0 +1,43 @@ +ROOT@[0; 56) + FN_DEF@[0; 55) + FN_KW@[0; 2) + WHITESPACE@[2; 3) + NAME@[3; 6) + IDENT@[3; 6) "foo" + PARAM_LIST@[6; 8) + L_PAREN@[6; 7) + R_PAREN@[7; 8) + WHITESPACE@[8; 9) + BLOCK@[9; 55) + L_CURLY@[9; 10) + WHITESPACE@[10; 15) + EXPR_STMT@[15; 38) + CALL_EXPR@[15; 38) + PATH_EXPR@[15; 18) + PATH@[15; 18) + PATH_SEGMENT@[15; 18) + NAME_REF@[15; 18) + IDENT@[15; 18) "foo" + ARG_LIST@[18; 38) + L_PAREN@[18; 19) + WHITESPACE@[19; 28) + LITERAL@[28; 29) + INT_NUMBER@[28; 29) "1" + COMMA@[29; 30) + WHITESPACE@[30; 31) + LITERAL@[31; 32) + INT_NUMBER@[31; 32) "2" + WHITESPACE@[32; 37) + R_PAREN@[37; 38) + err: `expected SEMI` + WHITESPACE@[38; 43) + EXPR_STMT@[43; 53) + RETURN_EXPR@[43; 52) + RETURN_KW@[43; 49) + WHITESPACE@[49; 50) + LITERAL@[50; 52) + INT_NUMBER@[50; 52) "92" + SEMI@[52; 53) + WHITESPACE@[53; 54) + R_CURLY@[54; 55) + WHITESPACE@[55; 56)