From ca52cf1ecd4f65ff2a8c3953c35b006e73a60ea8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jan 2019 18:26:29 +0300 Subject: remove Cancelable from Module API --- crates/ra_hir/src/code_model_api.rs | 6 +++--- crates/ra_hir/src/code_model_impl/module.rs | 19 ++++++++----------- crates/ra_hir/src/impl_block.rs | 2 +- 3 files changed, 12 insertions(+), 15 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 5db53a34f..aed0ea958 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -78,12 +78,12 @@ pub enum Problem { impl Module { /// Name of this module. - pub fn name(&self, db: &impl HirDatabase) -> Cancelable> { + pub fn name(&self, db: &impl HirDatabase) -> Option { self.name_impl(db) } /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. - pub fn definition_source(&self, db: &impl HirDatabase) -> Cancelable<(FileId, ModuleSource)> { + pub fn definition_source(&self, db: &impl HirDatabase) -> (FileId, ModuleSource) { self.definition_source_impl(db) } @@ -92,7 +92,7 @@ impl Module { pub fn declaration_source( &self, db: &impl HirDatabase, - ) -> Cancelable)>> { + ) -> Option<(FileId, TreeArc)> { self.declaration_source_impl(db) } diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index 67808d282..127dcc570 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -30,17 +30,14 @@ impl Module { Module::new(def_id) } - pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Cancelable> { + pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Option { let loc = self.def_id.loc(db); let module_tree = db.module_tree(loc.source_root_id); - let link = ctry!(loc.module_id.parent_link(&module_tree)); - Ok(Some(link.name(&module_tree).clone())) + let link = loc.module_id.parent_link(&module_tree)?; + Some(link.name(&module_tree).clone()) } - pub fn definition_source_impl( - &self, - db: &impl HirDatabase, - ) -> Cancelable<(FileId, ModuleSource)> { + pub fn definition_source_impl(&self, db: &impl HirDatabase) -> (FileId, ModuleSource) { let loc = self.def_id.loc(db); let file_id = loc.source_item_id.file_id.as_original_file(); let syntax_node = db.file_item(loc.source_item_id); @@ -50,23 +47,23 @@ impl Module { let module = ast::Module::cast(&syntax_node).unwrap(); ModuleSource::Module(module.to_owned()) }; - Ok((file_id, module_source)) + (file_id, module_source) } pub fn declaration_source_impl( &self, db: &impl HirDatabase, - ) -> Cancelable)>> { + ) -> Option<(FileId, TreeArc)> { let loc = self.def_id.loc(db); let module_tree = db.module_tree(loc.source_root_id); - let link = ctry!(loc.module_id.parent_link(&module_tree)); + let link = loc.module_id.parent_link(&module_tree)?; let file_id = link .owner(&module_tree) .source(&module_tree) .file_id .as_original_file(); let src = link.source(&module_tree, db); - Ok(Some((file_id, src))) + Some((file_id, src)) } pub(crate) fn krate_impl(&self, db: &impl HirDatabase) -> Cancelable> { diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index c9a9fb99f..ce9087b49 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs @@ -167,7 +167,7 @@ impl ModuleImplBlocks { } fn collect(&mut self, db: &impl HirDatabase, module: Module) -> Cancelable<()> { - let (file_id, module_source) = module.definition_source(db)?; + let (file_id, module_source) = module.definition_source(db); let node = match &module_source { ModuleSource::SourceFile(node) => node.syntax(), ModuleSource::Module(node) => node -- cgit v1.2.3