From de930237ffb5bec9489443477a5b4ff964f56b0e Mon Sep 17 00:00:00 2001 From: zjy Date: Wed, 26 Jun 2019 11:36:14 +0800 Subject: fixed #1384 --- crates/ra_parser/src/grammar/expressions.rs | 11 +++++++++++ crates/ra_parser/src/grammar/items.rs | 16 +++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) (limited to 'crates/ra_parser') diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index 795dccea1..298030cb9 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs @@ -181,6 +181,17 @@ pub(crate) fn expr_block_contents(p: &mut Parser) { // fn foo(){ // ;;;some_expr();;;;{;;;};;;;Ok(()) // } + + // test nocontentexpr_after_item + // fn simple_function() { + // enum LocalEnum { + // One, + // Two, + // }; + // fn f() {}; + // struct S {}; + // } + if p.current() == T![;] { p.bump(); continue; diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 424d0476d..543af7c4b 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -38,7 +38,15 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF let m = p.start(); attributes::outer_attributes(p); let m = match maybe_item(p, m, flavor) { - Ok(()) => return, + Ok(()) => { + if p.at(T![;]) { + p.err_and_bump( + "expected item, found `;`\n\ + consider removing this semicolon", + ); + } + return; + } Err(m) => m, }; if paths::is_path_start(p) { @@ -263,12 +271,6 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> { } _ => return Err(m), }; - if p.at(T![;]) { - p.err_and_bump( - "expected item, found `;`\n\ - consider removing this semicolon", - ); - } Ok(()) } -- cgit v1.2.3