From 8ba9c2d4cedbcf8f1d2c644733d2b06fa1984d22 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jan 2019 20:54:18 +0300 Subject: remove Cancelable from type inference --- crates/ra_hir/src/ty/method_resolution.rs | 37 ++++++++++++++----------------- crates/ra_hir/src/ty/tests.rs | 6 ++--- 2 files changed, 20 insertions(+), 23 deletions(-) (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index 0676a989d..b221bd142 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs @@ -6,7 +6,7 @@ use std::sync::Arc; use rustc_hash::FxHashMap; -use ra_db::{Cancelable, SourceRootId}; +use ra_db::SourceRootId; use crate::{HirDatabase, DefId, module_tree::ModuleId, Module, Crate, Name, Function, impl_block::{ImplId, ImplBlock, ImplItem}}; use super::Ty; @@ -42,7 +42,7 @@ impl CrateImplBlocks { &'a self, db: &'a impl HirDatabase, ty: &Ty, - ) -> impl Iterator> + 'a { + ) -> impl Iterator + 'a { let fingerprint = TyFingerprint::for_impl(ty); fingerprint .and_then(|f| self.impls.get(&f)) @@ -50,11 +50,11 @@ impl CrateImplBlocks { .flat_map(|i| i.iter()) .map(move |(module_id, impl_id)| { let module_impl_blocks = db.impls_in_module(self.source_root_id, *module_id); - Ok(ImplBlock::from_id(module_impl_blocks, *impl_id)) + ImplBlock::from_id(module_impl_blocks, *impl_id) }) } - fn collect_recursive(&mut self, db: &impl HirDatabase, module: Module) -> Cancelable<()> { + fn collect_recursive(&mut self, db: &impl HirDatabase, module: Module) { let module_id = module.def_id.loc(db).module_id; let module_impl_blocks = db.impls_in_module(self.source_root_id, module_id); @@ -76,16 +76,14 @@ impl CrateImplBlocks { } for child in module.children(db) { - self.collect_recursive(db, child)?; + self.collect_recursive(db, child); } - - Ok(()) } pub(crate) fn impls_in_crate_query( db: &impl HirDatabase, krate: Crate, - ) -> Cancelable> { + ) -> Arc { let crate_graph = db.crate_graph(); let file_id = crate_graph.crate_root(krate.crate_id); let source_root_id = db.file_source_root(file_id); @@ -94,9 +92,9 @@ impl CrateImplBlocks { impls: FxHashMap::default(), }; if let Some(module) = krate.root_module(db) { - crate_impl_blocks.collect_recursive(db, module)?; + crate_impl_blocks.collect_recursive(db, module); } - Ok(Arc::new(crate_impl_blocks)) + Arc::new(crate_impl_blocks) } } @@ -111,13 +109,13 @@ impl Ty { // TODO: cache this as a query? // - if so, what signature? (TyFingerprint, Name)? // - or maybe cache all names and def_ids of methods per fingerprint? - pub fn lookup_method(self, db: &impl HirDatabase, name: &Name) -> Cancelable> { + pub fn lookup_method(self, db: &impl HirDatabase, name: &Name) -> Option { self.iterate_methods(db, |f| { let sig = f.signature(db); if sig.name() == name && sig.has_self_param() { - Ok(Some(f.def_id())) + Some(f.def_id()) } else { - Ok(None) + None } }) } @@ -127,8 +125,8 @@ impl Ty { pub fn iterate_methods( self, db: &impl HirDatabase, - mut callback: impl FnMut(Function) -> Cancelable>, - ) -> Cancelable> { + mut callback: impl FnMut(Function) -> Option, + ) -> Option { // For method calls, rust first does any number of autoderef, and then one // autoref (i.e. when the method takes &self or &mut self). We just ignore // the autoref currently -- when we find a method matching the given name, @@ -143,15 +141,14 @@ impl Ty { Some(krate) => krate, None => continue, }; - let impls = db.impls_in_crate(krate)?; + let impls = db.impls_in_crate(krate); for impl_block in impls.lookup_impl_blocks(db, &derefed_ty) { - let impl_block = impl_block?; for item in impl_block.items() { match item { ImplItem::Method(f) => { - if let Some(result) = callback(f.clone())? { - return Ok(Some(result)); + if let Some(result) = callback(f.clone()) { + return Some(result); } } _ => {} @@ -159,6 +156,6 @@ impl Ty { } } } - Ok(None) + None } } diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index b44ac9987..929fee04c 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -321,7 +321,7 @@ fn infer(content: &str) -> String { .filter_map(ast::FnDef::cast) { let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap(); - let inference_result = func.infer(&db).unwrap(); + let inference_result = func.infer(&db); let body_syntax_mapping = func.body_syntax_mapping(&db); let mut types = Vec::new(); for (pat, ty) in inference_result.type_of_pat.iter() { @@ -405,7 +405,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() { let func = source_binder::function_from_position(&db, pos).unwrap(); { let events = db.log_executed(|| { - func.infer(&db).unwrap(); + func.infer(&db); }); assert!(format!("{:?}", events).contains("infer")) } @@ -424,7 +424,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() { { let events = db.log_executed(|| { - func.infer(&db).unwrap(); + func.infer(&db); }); assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events) } -- cgit v1.2.3