From 3d9c2beb8e0d4e0fbaded7dac259cadf7616a3ad Mon Sep 17 00:00:00 2001 From: pcpthm Date: Mon, 18 Mar 2019 13:03:04 +0900 Subject: Apply stylistic changes suggested --- crates/ra_parser/src/grammar/expressions.rs | 8 ++++---- crates/ra_parser/src/grammar/items.rs | 23 ++++++++++------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index 9839846f1..6d3e379a3 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs @@ -54,7 +54,7 @@ pub(crate) fn expr_block_contents(p: &mut Parser) { // test block_items // fn a() { fn b() {} } - let mut m = p.start(); + let m = p.start(); let has_attrs = p.at(POUND); attributes::outer_attributes(p); if p.at(LET_KW) { @@ -62,9 +62,9 @@ pub(crate) fn expr_block_contents(p: &mut Parser) { continue; } - m = match items::maybe_item(p, m, items::ItemFlavor::Mod) { - Some(m) => m, - None => continue, + let m = match items::maybe_item(p, m, items::ItemFlavor::Mod) { + Ok(()) => continue, + Err(m) => m, }; // test pub_expr diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 5411589dd..94b93a02b 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -35,11 +35,11 @@ pub(super) const ITEM_RECOVERY_SET: TokenSet = token_set![ ]; pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemFlavor) { - let mut m = p.start(); + let m = p.start(); attributes::outer_attributes(p); - m = match maybe_item(p, m, flavor) { - Some(m) => m, - None => return, + let m = match maybe_item(p, m, flavor) { + Ok(()) => return, + Err(m) => m, }; if paths::is_path_start(p) { match macro_call(p) { @@ -66,11 +66,11 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF } } -pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Option { +pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Result<(), Marker> { opt_visibility(p); if let Some(kind) = items_without_modifiers(p) { m.complete(p, kind); - return None; + return Ok(()); } let mut has_mods = false; @@ -124,7 +124,6 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Optio FN_KW => { fn_def(p, flavor); m.complete(p, FN_DEF); - None } // test unsafe_trait @@ -138,7 +137,6 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Optio TRAIT_KW => { traits::trait_def(p); m.complete(p, TRAIT_DEF); - None } // test unsafe_impl @@ -152,18 +150,17 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Optio IMPL_KW => { traits::impl_block(p); m.complete(p, IMPL_BLOCK); - None } _ => { - if has_mods { + if !has_mods { + return Err(m); + } else { p.error("expected fn, trait or impl"); m.complete(p, ERROR); - None - } else { - Some(m) } } } + Ok(()) } fn items_without_modifiers(p: &mut Parser) -> Option { -- cgit v1.2.3