aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/code_model_impl/function.rs5
-rw-r--r--crates/ra_hir/src/db.rs2
-rw-r--r--crates/ra_hir/src/ids.rs20
-rw-r--r--crates/ra_hir/src/impl_block.rs12
-rw-r--r--crates/ra_hir/src/ty.rs12
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs10
6 files changed, 27 insertions, 34 deletions
diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs
index d34803e32..66d7e1713 100644
--- a/crates/ra_hir/src/code_model_impl/function.rs
+++ b/crates/ra_hir/src/code_model_impl/function.rs
@@ -2,7 +2,6 @@ mod scope;
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use ra_db::Cancelable;
6use ra_syntax::{TreeArc, ast::{self, NameOwner}}; 5use ra_syntax::{TreeArc, ast::{self, NameOwner}};
7 6
8use crate::{ 7use crate::{
@@ -24,12 +23,12 @@ impl Function {
24 db.body_hir(self.def_id) 23 db.body_hir(self.def_id)
25 } 24 }
26 25
27 pub(crate) fn module(&self, db: &impl HirDatabase) -> Cancelable<Module> { 26 pub(crate) fn module(&self, db: &impl HirDatabase) -> Module {
28 self.def_id.module(db) 27 self.def_id.module(db)
29 } 28 }
30 29
31 /// The containing impl block, if this is a method. 30 /// The containing impl block, if this is a method.
32 pub(crate) fn impl_block(&self, db: &impl HirDatabase) -> Cancelable<Option<ImplBlock>> { 31 pub(crate) fn impl_block(&self, db: &impl HirDatabase) -> Option<ImplBlock> {
33 self.def_id.impl_block(db) 32 self.def_id.impl_block(db)
34 } 33 }
35} 34}
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index 1466c3438..161a5e714 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -97,7 +97,7 @@ pub trait HirDatabase: SyntaxDatabase
97 use fn crate::module_tree::ModuleTree::module_tree_query; 97 use fn crate::module_tree::ModuleTree::module_tree_query;
98 } 98 }
99 99
100 fn impls_in_module(source_root_id: SourceRootId, module_id: ModuleId) -> Cancelable<Arc<ModuleImplBlocks>> { 100 fn impls_in_module(source_root_id: SourceRootId, module_id: ModuleId) -> Arc<ModuleImplBlocks> {
101 type ImplsInModuleQuery; 101 type ImplsInModuleQuery;
102 use fn crate::impl_block::impls_in_module; 102 use fn crate::impl_block::impls_in_module;
103 } 103 }
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 3cbf8070f..0d8e67547 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -1,4 +1,4 @@
1use ra_db::{SourceRootId, LocationIntener, Cancelable, FileId}; 1use ra_db::{SourceRootId, LocationIntener, FileId};
2use ra_syntax::{TreeArc, SyntaxKind, SyntaxNode, SourceFile, AstNode, ast}; 2use ra_syntax::{TreeArc, SyntaxKind, SyntaxNode, SourceFile, AstNode, ast};
3use ra_arena::{Arena, RawId, impl_arena_id}; 3use ra_arena::{Arena, RawId, impl_arena_id};
4 4
@@ -205,25 +205,21 @@ impl DefId {
205 } 205 }
206 206
207 /// For a module, returns that module; for any other def, returns the containing module. 207 /// For a module, returns that module; for any other def, returns the containing module.
208 pub fn module(self, db: &impl HirDatabase) -> Cancelable<Module> { 208 pub fn module(self, db: &impl HirDatabase) -> Module {
209 let loc = self.loc(db); 209 let loc = self.loc(db);
210 Ok(Module::from_module_id( 210 Module::from_module_id(db, loc.source_root_id, loc.module_id)
211 db,
212 loc.source_root_id,
213 loc.module_id,
214 ))
215 } 211 }
216 212
217 /// Returns the containing crate. 213 /// Returns the containing crate.
218 pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> { 214 pub fn krate(&self, db: &impl HirDatabase) -> Option<Crate> {
219 Ok(self.module(db)?.krate(db)) 215 self.module(db).krate(db)
220 } 216 }
221 217
222 /// Returns the containing impl block, if this is an impl item. 218 /// Returns the containing impl block, if this is an impl item.
223 pub fn impl_block(self, db: &impl HirDatabase) -> Cancelable<Option<ImplBlock>> { 219 pub fn impl_block(self, db: &impl HirDatabase) -> Option<ImplBlock> {
224 let loc = self.loc(db); 220 let loc = self.loc(db);
225 let module_impls = db.impls_in_module(loc.source_root_id, loc.module_id)?; 221 let module_impls = db.impls_in_module(loc.source_root_id, loc.module_id);
226 Ok(ImplBlock::containing(module_impls, self)) 222 ImplBlock::containing(module_impls, self)
227 } 223 }
228} 224}
229 225
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index ce9087b49..ab996a12c 100644
--- a/crates/ra_hir/src/impl_block.rs
+++ b/crates/ra_hir/src/impl_block.rs
@@ -3,7 +3,7 @@ use rustc_hash::FxHashMap;
3 3
4use ra_arena::{Arena, RawId, impl_arena_id}; 4use ra_arena::{Arena, RawId, impl_arena_id};
5use ra_syntax::ast::{self, AstNode}; 5use ra_syntax::ast::{self, AstNode};
6use ra_db::{LocationIntener, Cancelable, SourceRootId}; 6use ra_db::{LocationIntener, SourceRootId};
7 7
8use crate::{ 8use crate::{
9 DefId, DefLoc, DefKind, SourceItemId, SourceFileItems, 9 DefId, DefLoc, DefKind, SourceItemId, SourceFileItems,
@@ -166,7 +166,7 @@ impl ModuleImplBlocks {
166 } 166 }
167 } 167 }
168 168
169 fn collect(&mut self, db: &impl HirDatabase, module: Module) -> Cancelable<()> { 169 fn collect(&mut self, db: &impl HirDatabase, module: Module) {
170 let (file_id, module_source) = module.definition_source(db); 170 let (file_id, module_source) = module.definition_source(db);
171 let node = match &module_source { 171 let node = match &module_source {
172 ModuleSource::SourceFile(node) => node.syntax(), 172 ModuleSource::SourceFile(node) => node.syntax(),
@@ -185,8 +185,6 @@ impl ModuleImplBlocks {
185 self.impls_by_def.insert(impl_item.def_id(), id); 185 self.impls_by_def.insert(impl_item.def_id(), id);
186 } 186 }
187 } 187 }
188
189 Ok(())
190 } 188 }
191} 189}
192 190
@@ -194,9 +192,9 @@ pub(crate) fn impls_in_module(
194 db: &impl HirDatabase, 192 db: &impl HirDatabase,
195 source_root_id: SourceRootId, 193 source_root_id: SourceRootId,
196 module_id: ModuleId, 194 module_id: ModuleId,
197) -> Cancelable<Arc<ModuleImplBlocks>> { 195) -> Arc<ModuleImplBlocks> {
198 let mut result = ModuleImplBlocks::new(); 196 let mut result = ModuleImplBlocks::new();
199 let module = Module::from_module_id(db, source_root_id, module_id); 197 let module = Module::from_module_id(db, source_root_id, module_id);
200 result.collect(db, module)?; 198 result.collect(db, module);
201 Ok(Arc::new(result)) 199 Arc::new(result)
202} 200}
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 6df7820ea..e5f8ffc2e 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -447,8 +447,8 @@ impl fmt::Display for Ty {
447/// function body. 447/// function body.
448fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable<Ty> { 448fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable<Ty> {
449 let signature = f.signature(db); 449 let signature = f.signature(db);
450 let module = f.module(db)?; 450 let module = f.module(db);
451 let impl_block = f.impl_block(db)?; 451 let impl_block = f.impl_block(db);
452 // TODO we ignore type parameters for now 452 // TODO we ignore type parameters for now
453 let input = signature 453 let input = signature
454 .params() 454 .params()
@@ -517,8 +517,8 @@ pub(super) fn type_for_field(
517 def_id 517 def_id
518 ), 518 ),
519 }; 519 };
520 let module = def_id.module(db)?; 520 let module = def_id.module(db);
521 let impl_block = def_id.impl_block(db)?; 521 let impl_block = def_id.impl_block(db);
522 let type_ref = ctry!(variant_data.get_field_type_ref(&field)); 522 let type_ref = ctry!(variant_data.get_field_type_ref(&field));
523 Ok(Some(Ty::from_hir( 523 Ok(Some(Ty::from_hir(
524 db, 524 db,
@@ -1207,8 +1207,8 @@ pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceRe
1207 let function = Function::new(def_id); // TODO: consts also need inference 1207 let function = Function::new(def_id); // TODO: consts also need inference
1208 let body = function.body(db); 1208 let body = function.body(db);
1209 let scopes = db.fn_scopes(def_id); 1209 let scopes = db.fn_scopes(def_id);
1210 let module = function.module(db)?; 1210 let module = function.module(db);
1211 let impl_block = function.impl_block(db)?; 1211 let impl_block = function.impl_block(db);
1212 let mut ctx = InferenceContext::new(db, body, scopes, module, impl_block); 1212 let mut ctx = InferenceContext::new(db, body, scopes, module, impl_block);
1213 1213
1214 let signature = function.signature(db); 1214 let signature = function.signature(db);
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index c7fbcfd06..94c5124a9 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -49,14 +49,14 @@ impl CrateImplBlocks {
49 .into_iter() 49 .into_iter()
50 .flat_map(|i| i.iter()) 50 .flat_map(|i| i.iter())
51 .map(move |(module_id, impl_id)| { 51 .map(move |(module_id, impl_id)| {
52 let module_impl_blocks = db.impls_in_module(self.source_root_id, *module_id)?; 52 let module_impl_blocks = db.impls_in_module(self.source_root_id, *module_id);
53 Ok(ImplBlock::from_id(module_impl_blocks, *impl_id)) 53 Ok(ImplBlock::from_id(module_impl_blocks, *impl_id))
54 }) 54 })
55 } 55 }
56 56
57 fn collect_recursive(&mut self, db: &impl HirDatabase, module: Module) -> Cancelable<()> { 57 fn collect_recursive(&mut self, db: &impl HirDatabase, module: Module) -> Cancelable<()> {
58 let module_id = module.def_id.loc(db).module_id; 58 let module_id = module.def_id.loc(db).module_id;
59 let module_impl_blocks = db.impls_in_module(self.source_root_id, module_id)?; 59 let module_impl_blocks = db.impls_in_module(self.source_root_id, module_id);
60 60
61 for (impl_id, impl_data) in module_impl_blocks.impls.iter() { 61 for (impl_id, impl_data) in module_impl_blocks.impls.iter() {
62 let impl_block = ImplBlock::from_id(Arc::clone(&module_impl_blocks), impl_id); 62 let impl_block = ImplBlock::from_id(Arc::clone(&module_impl_blocks), impl_id);
@@ -100,10 +100,10 @@ impl CrateImplBlocks {
100 } 100 }
101} 101}
102 102
103fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Cancelable<Option<Crate>> { 103fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Option<Crate> {
104 match ty { 104 match ty {
105 Ty::Adt { def_id, .. } => def_id.krate(db), 105 Ty::Adt { def_id, .. } => def_id.krate(db),
106 _ => Ok(None), 106 _ => None,
107 } 107 }
108} 108}
109 109
@@ -139,7 +139,7 @@ impl Ty {
139 // rustc does an autoderef and then autoref again). 139 // rustc does an autoderef and then autoref again).
140 140
141 for derefed_ty in self.autoderef(db) { 141 for derefed_ty in self.autoderef(db) {
142 let krate = match def_crate(db, &derefed_ty)? { 142 let krate = match def_crate(db, &derefed_ty) {
143 Some(krate) => krate, 143 Some(krate) => krate,
144 None => continue, 144 None => continue,
145 }; 145 };