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/src') 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 From c159e414b42e2fd43ed88bbf4113fbe8c8e372fe Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jan 2019 18:30:58 +0300 Subject: remove Cancelable from Module API, part 2 --- crates/ra_hir/src/code_model_api.rs | 14 +++++++------- crates/ra_hir/src/code_model_impl/module.rs | 30 +++++++++++++---------------- crates/ra_hir/src/ids.rs | 2 +- crates/ra_hir/src/ty/method_resolution.rs | 2 +- 4 files changed, 22 insertions(+), 26 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index aed0ea958..81638e384 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -97,14 +97,14 @@ impl Module { } /// Returns the crate this module is part of. - pub fn krate(&self, db: &impl HirDatabase) -> Cancelable> { + pub fn krate(&self, db: &impl HirDatabase) -> Option { self.krate_impl(db) } /// Topmost parent of this module. Every module has a `crate_root`, but some /// might be missing `krate`. This can happen if a module's file is not included /// in the module tree of any target in Cargo.toml. - pub fn crate_root(&self, db: &impl HirDatabase) -> Cancelable { + pub fn crate_root(&self, db: &impl HirDatabase) -> Module { self.crate_root_impl(db) } @@ -114,23 +114,23 @@ impl Module { } /// Iterates over all child modules. - pub fn children(&self, db: &impl HirDatabase) -> Cancelable> { + pub fn children(&self, db: &impl HirDatabase) -> impl Iterator { self.children_impl(db) } /// Finds a parent module. - pub fn parent(&self, db: &impl HirDatabase) -> Cancelable> { + pub fn parent(&self, db: &impl HirDatabase) -> Option { self.parent_impl(db) } - pub fn path_to_root(&self, db: &impl HirDatabase) -> Cancelable> { + pub fn path_to_root(&self, db: &impl HirDatabase) -> Vec { let mut res = vec![self.clone()]; let mut curr = self.clone(); - while let Some(next) = curr.parent(db)? { + while let Some(next) = curr.parent(db) { res.push(next.clone()); curr = next } - Ok(res) + res } /// Returns a `ModuleScope`: a set of items, visible in this module. diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index 127dcc570..8668d6c8a 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -66,21 +66,21 @@ impl Module { Some((file_id, src)) } - pub(crate) fn krate_impl(&self, db: &impl HirDatabase) -> Cancelable> { - let root = self.crate_root(db)?; + pub(crate) fn krate_impl(&self, db: &impl HirDatabase) -> Option { + let root = self.crate_root(db); let loc = root.def_id.loc(db); let file_id = loc.source_item_id.file_id.as_original_file(); let crate_graph = db.crate_graph(); - let crate_id = ctry!(crate_graph.crate_id_for_crate_root(file_id)); - Ok(Some(Crate::new(crate_id))) + let crate_id = crate_graph.crate_id_for_crate_root(file_id)?; + Some(Crate::new(crate_id)) } - pub(crate) fn crate_root_impl(&self, db: &impl HirDatabase) -> Cancelable { + pub(crate) fn crate_root_impl(&self, db: &impl HirDatabase) -> Module { let loc = self.def_id.loc(db); let module_tree = db.module_tree(loc.source_root_id); let module_id = loc.module_id.crate_root(&module_tree); - Ok(Module::from_module_id(db, loc.source_root_id, module_id)) + Module::from_module_id(db, loc.source_root_id, module_id) } /// Finds a child module with the specified name. @@ -92,7 +92,7 @@ impl Module { } /// Iterates over all child modules. - pub fn children_impl(&self, db: &impl HirDatabase) -> Cancelable> { + pub fn children_impl(&self, db: &impl HirDatabase) -> impl Iterator { // FIXME this should be implementable without collecting into a vec, but // it's kind of hard since the iterator needs to keep a reference to the // module tree. @@ -103,18 +103,14 @@ impl Module { .children(&module_tree) .map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id)) .collect::>(); - Ok(children.into_iter()) + children.into_iter() } - pub fn parent_impl(&self, db: &impl HirDatabase) -> Cancelable> { + pub fn parent_impl(&self, db: &impl HirDatabase) -> Option { let loc = self.def_id.loc(db); let module_tree = db.module_tree(loc.source_root_id); - let parent_id = ctry!(loc.module_id.parent(&module_tree)); - Ok(Some(Module::from_module_id( - db, - loc.source_root_id, - parent_id, - ))) + let parent_id = loc.module_id.parent(&module_tree)?; + Some(Module::from_module_id(db, loc.source_root_id, parent_id)) } /// Returns a `ModuleScope`: a set of items, visible in this module. @@ -132,10 +128,10 @@ impl Module { ) -> Cancelable> { let mut curr_per_ns = PerNs::types( match path.kind { - PathKind::Crate => self.crate_root(db)?, + PathKind::Crate => self.crate_root(db), PathKind::Self_ | PathKind::Plain => self.clone(), PathKind::Super => { - if let Some(p) = self.parent(db)? { + if let Some(p) = self.parent(db) { p } else { return Ok(PerNs::none()); diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index d7cc9b4ca..7b572061a 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs @@ -217,7 +217,7 @@ impl DefId { /// Returns the containing crate. pub fn krate(&self, db: &impl HirDatabase) -> Cancelable> { - Ok(self.module(db)?.krate(db)?) + Ok(self.module(db)?.krate(db)) } /// Returns the containing impl block, if this is an impl item. diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index 7c3839388..f0da2ee2b 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs @@ -75,7 +75,7 @@ impl CrateImplBlocks { } } - for child in module.children(db)? { + for child in module.children(db) { self.collect_recursive(db, child)?; } -- cgit v1.2.3 From 8af9a18660f9b2f34da902f43c1eef856af1cfca Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jan 2019 18:33:26 +0300 Subject: remove Cancelable from Crate API --- crates/ra_hir/src/code_model_api.rs | 6 +++--- crates/ra_hir/src/code_model_impl/krate.rs | 8 ++++---- crates/ra_hir/src/nameres.rs | 4 ++-- crates/ra_hir/src/ty/method_resolution.rs | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 81638e384..db270b871 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -33,10 +33,10 @@ impl Crate { pub fn crate_id(&self) -> CrateId { self.crate_id } - pub fn dependencies(&self, db: &impl HirDatabase) -> Cancelable> { - Ok(self.dependencies_impl(db)) + pub fn dependencies(&self, db: &impl HirDatabase) -> Vec { + self.dependencies_impl(db) } - pub fn root_module(&self, db: &impl HirDatabase) -> Cancelable> { + pub fn root_module(&self, db: &impl HirDatabase) -> Option { self.root_module_impl(db) } } diff --git a/crates/ra_hir/src/code_model_impl/krate.rs b/crates/ra_hir/src/code_model_impl/krate.rs index 712c6c86a..8c6e34873 100644 --- a/crates/ra_hir/src/code_model_impl/krate.rs +++ b/crates/ra_hir/src/code_model_impl/krate.rs @@ -1,4 +1,4 @@ -use ra_db::{CrateId, Cancelable}; +use ra_db::CrateId; use crate::{ HirFileId, Crate, CrateDependency, AsName, DefLoc, DefKind, Module, SourceItemId, @@ -20,7 +20,7 @@ impl Crate { }) .collect() } - pub(crate) fn root_module_impl(&self, db: &impl HirDatabase) -> Cancelable> { + pub(crate) fn root_module_impl(&self, db: &impl HirDatabase) -> Option { let crate_graph = db.crate_graph(); let file_id = crate_graph.crate_root(self.crate_id); let source_root_id = db.file_source_root(file_id); @@ -31,7 +31,7 @@ impl Crate { file_id, item_id: None, }; - let module_id = ctry!(module_tree.find_module_by_source(source)); + let module_id = module_tree.find_module_by_source(source)?; let def_loc = DefLoc { kind: DefKind::Module, @@ -42,6 +42,6 @@ impl Crate { let def_id = def_loc.id(db); let module = Module::new(def_id); - Ok(Some(module)) + Some(module) } } diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index edb3b1e64..e51cbe786 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -353,8 +353,8 @@ where if let Some(crate_id) = crate_graph.crate_id_for_crate_root(file_id.as_original_file()) { let krate = Crate::new(crate_id); - for dep in krate.dependencies(self.db)? { - if let Some(module) = dep.krate.root_module(self.db)? { + for dep in krate.dependencies(self.db) { + if let Some(module) = dep.krate.root_module(self.db) { let def_id = module.def_id; self.add_module_item( &mut module_items, diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index f0da2ee2b..c7fbcfd06 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs @@ -93,7 +93,7 @@ impl CrateImplBlocks { source_root_id, impls: FxHashMap::default(), }; - if let Some(module) = krate.root_module(db)? { + if let Some(module) = krate.root_module(db) { crate_impl_blocks.collect_recursive(db, module)?; } Ok(Arc::new(crate_impl_blocks)) -- cgit v1.2.3