From aa7fd563a4b8817223ac50fa22cd946ce354f47d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 27 Nov 2018 18:45:16 +0300 Subject: use ctry --- crates/ra_analysis/src/completion/mod.rs | 5 +---- crates/ra_analysis/src/descriptors/module/mod.rs | 11 +---------- crates/ra_analysis/src/imp.rs | 10 ++-------- crates/ra_analysis/src/lib.rs | 9 +++++++++ 4 files changed, 13 insertions(+), 22 deletions(-) (limited to 'crates') diff --git a/crates/ra_analysis/src/completion/mod.rs b/crates/ra_analysis/src/completion/mod.rs index c7717ab61..5ef278127 100644 --- a/crates/ra_analysis/src/completion/mod.rs +++ b/crates/ra_analysis/src/completion/mod.rs @@ -38,10 +38,7 @@ pub(crate) fn completions( original_file.reparse(&edit) }; - let module = match ModuleDescriptor::guess_from_position(db, position)? { - None => return Ok(None), - Some(it) => it, - }; + let module = ctry!(ModuleDescriptor::guess_from_position(db, position)?); let mut res = Vec::new(); let mut has_completions = false; diff --git a/crates/ra_analysis/src/descriptors/module/mod.rs b/crates/ra_analysis/src/descriptors/module/mod.rs index 51bc84bf1..764e19ce0 100644 --- a/crates/ra_analysis/src/descriptors/module/mod.rs +++ b/crates/ra_analysis/src/descriptors/module/mod.rs @@ -17,7 +17,7 @@ use crate::{ descriptors::{Path, PathKind, DescriptorDatabase}, input::SourceRootId, arena::{Arena, Id}, - loc2id::DefLoc, + loc2id::{DefLoc, DefId}, }; pub(crate) use self::nameres::ModuleScope; @@ -153,15 +153,6 @@ impl ModuleDescriptor { db: &impl DescriptorDatabase, path: Path, ) -> Cancelable> { - macro_rules! ctry { - ($expr:expr) => { - match $expr { - None => return Ok(None), - Some(it) => it, - } - }; - }; - let mut curr = match path.kind { PathKind::Crate => self.crate_root(), PathKind::Self_ | PathKind::Plain => self.clone(), diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index ad6b52371..8a41b3152 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -450,14 +450,8 @@ impl AnalysisImpl { let syntax = file.syntax(); // Find the calling expression and it's NameRef - let calling_node = match FnCallNode::with_node(syntax, position.offset) { - Some(node) => node, - None => return Ok(None), - }; - let name_ref = match calling_node.name_ref() { - Some(name) => name, - None => return Ok(None), - }; + let calling_node = ctry!(FnCallNode::with_node(syntax, position.offset)); + let name_ref = ctry!(calling_node.name_ref()); // Resolve the function's NameRef (NOTE: this isn't entirely accurate). let file_symbols = self.index_resolve(name_ref)?; diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index cedbd1fc8..0fbfd8a40 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -9,6 +9,15 @@ extern crate relative_path; extern crate rustc_hash; extern crate salsa; +macro_rules! ctry { + ($expr:expr) => { + match $expr { + None => return Ok(None), + Some(it) => it, + } + }; +} + mod arena; mod db; mod loc2id; -- cgit v1.2.3