diff options
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model_impl/function.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model_impl/module.rs | 33 | ||||
-rw-r--r-- | crates/ra_hir/src/db.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/ids.rs | 20 | ||||
-rw-r--r-- | crates/ra_hir/src/impl_block.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres.rs | 42 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir/src/query_definitions.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir/src/ty.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/method_resolution.rs | 10 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_scope.rs | 2 | ||||
-rw-r--r-- | crates/ra_ide_api/src/goto_definition.rs | 2 |
14 files changed, 79 insertions, 100 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 4d7925ac4..7ccd29e2f 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -134,11 +134,11 @@ impl Module { | |||
134 | } | 134 | } |
135 | 135 | ||
136 | /// Returns a `ModuleScope`: a set of items, visible in this module. | 136 | /// Returns a `ModuleScope`: a set of items, visible in this module. |
137 | pub fn scope(&self, db: &impl HirDatabase) -> Cancelable<ModuleScope> { | 137 | pub fn scope(&self, db: &impl HirDatabase) -> ModuleScope { |
138 | self.scope_impl(db) | 138 | self.scope_impl(db) |
139 | } | 139 | } |
140 | 140 | ||
141 | pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> Cancelable<PerNs<DefId>> { | 141 | pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs<DefId> { |
142 | self.resolve_path_impl(db, path) | 142 | self.resolve_path_impl(db, path) |
143 | } | 143 | } |
144 | 144 | ||
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 | ||
3 | use std::sync::Arc; | 3 | use std::sync::Arc; |
4 | 4 | ||
5 | use ra_db::Cancelable; | ||
6 | use ra_syntax::{TreeArc, ast::{self, NameOwner}}; | 5 | use ra_syntax::{TreeArc, ast::{self, NameOwner}}; |
7 | 6 | ||
8 | use crate::{ | 7 | use 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/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index 331b0500e..04301ae53 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs | |||
@@ -114,18 +114,13 @@ impl Module { | |||
114 | } | 114 | } |
115 | 115 | ||
116 | /// Returns a `ModuleScope`: a set of items, visible in this module. | 116 | /// Returns a `ModuleScope`: a set of items, visible in this module. |
117 | pub fn scope_impl(&self, db: &impl HirDatabase) -> Cancelable<ModuleScope> { | 117 | pub fn scope_impl(&self, db: &impl HirDatabase) -> ModuleScope { |
118 | let loc = self.def_id.loc(db); | 118 | let loc = self.def_id.loc(db); |
119 | let item_map = db.item_map(loc.source_root_id)?; | 119 | let item_map = db.item_map(loc.source_root_id); |
120 | let res = item_map.per_module[&loc.module_id].clone(); | 120 | item_map.per_module[&loc.module_id].clone() |
121 | Ok(res) | ||
122 | } | 121 | } |
123 | 122 | ||
124 | pub fn resolve_path_impl( | 123 | pub fn resolve_path_impl(&self, db: &impl HirDatabase, path: &Path) -> PerNs<DefId> { |
125 | &self, | ||
126 | db: &impl HirDatabase, | ||
127 | path: &Path, | ||
128 | ) -> Cancelable<PerNs<DefId>> { | ||
129 | let mut curr_per_ns = PerNs::types( | 124 | let mut curr_per_ns = PerNs::types( |
130 | match path.kind { | 125 | match path.kind { |
131 | PathKind::Crate => self.crate_root(db), | 126 | PathKind::Crate => self.crate_root(db), |
@@ -134,7 +129,7 @@ impl Module { | |||
134 | if let Some(p) = self.parent(db) { | 129 | if let Some(p) = self.parent(db) { |
135 | p | 130 | p |
136 | } else { | 131 | } else { |
137 | return Ok(PerNs::none()); | 132 | return PerNs::none(); |
138 | } | 133 | } |
139 | } | 134 | } |
140 | } | 135 | } |
@@ -146,7 +141,7 @@ impl Module { | |||
146 | let curr = if let Some(r) = curr_per_ns.as_ref().take_types() { | 141 | let curr = if let Some(r) = curr_per_ns.as_ref().take_types() { |
147 | r | 142 | r |
148 | } else { | 143 | } else { |
149 | return Ok(PerNs::none()); | 144 | return PerNs::none(); |
150 | }; | 145 | }; |
151 | let module = match curr.resolve(db) { | 146 | let module = match curr.resolve(db) { |
152 | Def::Module(it) => it, | 147 | Def::Module(it) => it, |
@@ -157,28 +152,28 @@ impl Module { | |||
157 | e.variants(db).into_iter().find(|(n, _variant)| n == name); | 152 | e.variants(db).into_iter().find(|(n, _variant)| n == name); |
158 | 153 | ||
159 | if let Some((_n, variant)) = matching_variant { | 154 | if let Some((_n, variant)) = matching_variant { |
160 | return Ok(PerNs::both(variant.def_id(), e.def_id())); | 155 | return PerNs::both(variant.def_id(), e.def_id()); |
161 | } else { | 156 | } else { |
162 | return Ok(PerNs::none()); | 157 | return PerNs::none(); |
163 | } | 158 | } |
164 | } else if segments.len() == idx { | 159 | } else if segments.len() == idx { |
165 | // enum | 160 | // enum |
166 | return Ok(PerNs::types(e.def_id())); | 161 | return PerNs::types(e.def_id()); |
167 | } else { | 162 | } else { |
168 | // malformed enum? | 163 | // malformed enum? |
169 | return Ok(PerNs::none()); | 164 | return PerNs::none(); |
170 | } | 165 | } |
171 | } | 166 | } |
172 | _ => return Ok(PerNs::none()), | 167 | _ => return PerNs::none(), |
173 | }; | 168 | }; |
174 | let scope = module.scope(db)?; | 169 | let scope = module.scope(db); |
175 | curr_per_ns = if let Some(r) = scope.get(&name) { | 170 | curr_per_ns = if let Some(r) = scope.get(&name) { |
176 | r.def_id | 171 | r.def_id |
177 | } else { | 172 | } else { |
178 | return Ok(PerNs::none()); | 173 | return PerNs::none(); |
179 | }; | 174 | }; |
180 | } | 175 | } |
181 | Ok(curr_per_ns) | 176 | curr_per_ns |
182 | } | 177 | } |
183 | 178 | ||
184 | pub fn problems_impl( | 179 | pub fn problems_impl( |
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index d20c03f43..161a5e714 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -87,7 +87,7 @@ pub trait HirDatabase: SyntaxDatabase | |||
87 | use fn query_definitions::input_module_items; | 87 | use fn query_definitions::input_module_items; |
88 | } | 88 | } |
89 | 89 | ||
90 | fn item_map(source_root_id: SourceRootId) -> Cancelable<Arc<ItemMap>> { | 90 | fn item_map(source_root_id: SourceRootId) -> Arc<ItemMap> { |
91 | type ItemMapQuery; | 91 | type ItemMapQuery; |
92 | use fn query_definitions::item_map; | 92 | use fn query_definitions::item_map; |
93 | } | 93 | } |
@@ -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 @@ | |||
1 | use ra_db::{SourceRootId, LocationIntener, Cancelable, FileId}; | 1 | use ra_db::{SourceRootId, LocationIntener, FileId}; |
2 | use ra_syntax::{TreeArc, SyntaxKind, SyntaxNode, SourceFile, AstNode, ast}; | 2 | use ra_syntax::{TreeArc, SyntaxKind, SyntaxNode, SourceFile, AstNode, ast}; |
3 | use ra_arena::{Arena, RawId, impl_arena_id}; | 3 | use 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 | ||
4 | use ra_arena::{Arena, RawId, impl_arena_id}; | 4 | use ra_arena::{Arena, RawId, impl_arena_id}; |
5 | use ra_syntax::ast::{self, AstNode}; | 5 | use ra_syntax::ast::{self, AstNode}; |
6 | use ra_db::{LocationIntener, Cancelable, SourceRootId}; | 6 | use ra_db::{LocationIntener, SourceRootId}; |
7 | 7 | ||
8 | use crate::{ | 8 | use 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/nameres.rs b/crates/ra_hir/src/nameres.rs index e51cbe786..484f668d0 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs | |||
@@ -22,7 +22,7 @@ use ra_syntax::{ | |||
22 | SyntaxKind::{self, *}, | 22 | SyntaxKind::{self, *}, |
23 | ast::{self, AstNode} | 23 | ast::{self, AstNode} |
24 | }; | 24 | }; |
25 | use ra_db::{SourceRootId, Cancelable, FileId}; | 25 | use ra_db::{SourceRootId, FileId}; |
26 | 26 | ||
27 | use crate::{ | 27 | use crate::{ |
28 | HirFileId, | 28 | HirFileId, |
@@ -319,30 +319,26 @@ where | |||
319 | } | 319 | } |
320 | } | 320 | } |
321 | 321 | ||
322 | pub(crate) fn resolve(mut self) -> Cancelable<ItemMap> { | 322 | pub(crate) fn resolve(mut self) -> ItemMap { |
323 | for (&module_id, items) in self.input.iter() { | 323 | for (&module_id, items) in self.input.iter() { |
324 | self.populate_module(module_id, Arc::clone(items))?; | 324 | self.populate_module(module_id, Arc::clone(items)); |
325 | } | 325 | } |
326 | 326 | ||
327 | loop { | 327 | loop { |
328 | let processed_imports_count = self.processed_imports.len(); | 328 | let processed_imports_count = self.processed_imports.len(); |
329 | for &module_id in self.input.keys() { | 329 | for &module_id in self.input.keys() { |
330 | self.db.check_canceled(); | 330 | self.db.check_canceled(); |
331 | self.resolve_imports(module_id)?; | 331 | self.resolve_imports(module_id); |
332 | } | 332 | } |
333 | if processed_imports_count == self.processed_imports.len() { | 333 | if processed_imports_count == self.processed_imports.len() { |
334 | // no new imports resolved | 334 | // no new imports resolved |
335 | break; | 335 | break; |
336 | } | 336 | } |
337 | } | 337 | } |
338 | Ok(self.result) | 338 | self.result |
339 | } | 339 | } |
340 | 340 | ||
341 | fn populate_module( | 341 | fn populate_module(&mut self, module_id: ModuleId, input: Arc<InputModuleItems>) { |
342 | &mut self, | ||
343 | module_id: ModuleId, | ||
344 | input: Arc<InputModuleItems>, | ||
345 | ) -> Cancelable<()> { | ||
346 | let mut module_items = ModuleScope::default(); | 342 | let mut module_items = ModuleScope::default(); |
347 | 343 | ||
348 | // Populate extern crates prelude | 344 | // Populate extern crates prelude |
@@ -415,7 +411,6 @@ where | |||
415 | } | 411 | } |
416 | 412 | ||
417 | self.result.per_module.insert(module_id, module_items); | 413 | self.result.per_module.insert(module_id, module_items); |
418 | Ok(()) | ||
419 | } | 414 | } |
420 | 415 | ||
421 | fn add_module_item(&self, module_items: &mut ModuleScope, name: Name, def_id: PerNs<DefId>) { | 416 | fn add_module_item(&self, module_items: &mut ModuleScope, name: Name, def_id: PerNs<DefId>) { |
@@ -426,24 +421,23 @@ where | |||
426 | module_items.items.insert(name, resolution); | 421 | module_items.items.insert(name, resolution); |
427 | } | 422 | } |
428 | 423 | ||
429 | fn resolve_imports(&mut self, module_id: ModuleId) -> Cancelable<()> { | 424 | fn resolve_imports(&mut self, module_id: ModuleId) { |
430 | for (i, import) in self.input[&module_id].imports.iter().enumerate() { | 425 | for (i, import) in self.input[&module_id].imports.iter().enumerate() { |
431 | if self.processed_imports.contains(&(module_id, i)) { | 426 | if self.processed_imports.contains(&(module_id, i)) { |
432 | // already done | 427 | // already done |
433 | continue; | 428 | continue; |
434 | } | 429 | } |
435 | if self.resolve_import(module_id, import)? { | 430 | if self.resolve_import(module_id, import) { |
436 | log::debug!("import {:?} resolved (or definite error)", import); | 431 | log::debug!("import {:?} resolved (or definite error)", import); |
437 | self.processed_imports.insert((module_id, i)); | 432 | self.processed_imports.insert((module_id, i)); |
438 | } | 433 | } |
439 | } | 434 | } |
440 | Ok(()) | ||
441 | } | 435 | } |
442 | 436 | ||
443 | fn resolve_import(&mut self, module_id: ModuleId, import: &Import) -> Cancelable<bool> { | 437 | fn resolve_import(&mut self, module_id: ModuleId, import: &Import) -> bool { |
444 | log::debug!("resolving import: {:?}", import); | 438 | log::debug!("resolving import: {:?}", import); |
445 | let ptr = match import.kind { | 439 | let ptr = match import.kind { |
446 | ImportKind::Glob => return Ok(false), | 440 | ImportKind::Glob => return false, |
447 | ImportKind::Named(ptr) => ptr, | 441 | ImportKind::Named(ptr) => ptr, |
448 | }; | 442 | }; |
449 | 443 | ||
@@ -455,7 +449,7 @@ where | |||
455 | None => { | 449 | None => { |
456 | // TODO: error | 450 | // TODO: error |
457 | log::debug!("super path in root module"); | 451 | log::debug!("super path in root module"); |
458 | return Ok(true); // this can't suddenly resolve if we just resolve some other imports | 452 | return true; // this can't suddenly resolve if we just resolve some other imports |
459 | } | 453 | } |
460 | } | 454 | } |
461 | } | 455 | } |
@@ -469,7 +463,7 @@ where | |||
469 | Some(res) if !res.def_id.is_none() => res.def_id, | 463 | Some(res) if !res.def_id.is_none() => res.def_id, |
470 | _ => { | 464 | _ => { |
471 | log::debug!("path segment {:?} not found", name); | 465 | log::debug!("path segment {:?} not found", name); |
472 | return Ok(false); | 466 | return false; |
473 | } | 467 | } |
474 | }; | 468 | }; |
475 | 469 | ||
@@ -481,7 +475,7 @@ where | |||
481 | "path segment {:?} resolved to value only, but is not last", | 475 | "path segment {:?} resolved to value only, but is not last", |
482 | name | 476 | name |
483 | ); | 477 | ); |
484 | return Ok(false); | 478 | return false; |
485 | }; | 479 | }; |
486 | curr = match type_def_id.loc(self.db) { | 480 | curr = match type_def_id.loc(self.db) { |
487 | DefLoc { | 481 | DefLoc { |
@@ -499,7 +493,7 @@ where | |||
499 | kind: PathKind::Crate, | 493 | kind: PathKind::Crate, |
500 | }; | 494 | }; |
501 | log::debug!("resolving {:?} in other source root", path); | 495 | log::debug!("resolving {:?} in other source root", path); |
502 | let def_id = module.resolve_path(self.db, &path)?; | 496 | let def_id = module.resolve_path(self.db, &path); |
503 | if !def_id.is_none() { | 497 | if !def_id.is_none() { |
504 | let name = path.segments.last().unwrap(); | 498 | let name = path.segments.last().unwrap(); |
505 | self.update(module_id, |items| { | 499 | self.update(module_id, |items| { |
@@ -515,10 +509,10 @@ where | |||
515 | import, | 509 | import, |
516 | def_id.map(|did| did.loc(self.db)) | 510 | def_id.map(|did| did.loc(self.db)) |
517 | ); | 511 | ); |
518 | return Ok(true); | 512 | return true; |
519 | } else { | 513 | } else { |
520 | log::debug!("rest of path did not resolve in other source root"); | 514 | log::debug!("rest of path did not resolve in other source root"); |
521 | return Ok(true); | 515 | return true; |
522 | } | 516 | } |
523 | } | 517 | } |
524 | } | 518 | } |
@@ -528,7 +522,7 @@ where | |||
528 | name, | 522 | name, |
529 | type_def_id.loc(self.db) | 523 | type_def_id.loc(self.db) |
530 | ); | 524 | ); |
531 | return Ok(true); // this resolved to a non-module, so the path won't ever resolve | 525 | return true; // this resolved to a non-module, so the path won't ever resolve |
532 | } | 526 | } |
533 | } | 527 | } |
534 | } else { | 528 | } else { |
@@ -547,7 +541,7 @@ where | |||
547 | }) | 541 | }) |
548 | } | 542 | } |
549 | } | 543 | } |
550 | Ok(true) | 544 | true |
551 | } | 545 | } |
552 | 546 | ||
553 | fn update(&mut self, module_id: ModuleId, f: impl FnOnce(&mut ModuleScope)) { | 547 | fn update(&mut self, module_id: ModuleId, f: impl FnOnce(&mut ModuleScope)) { |
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index ea8ab4c83..9a0474045 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs | |||
@@ -17,7 +17,7 @@ fn item_map(fixture: &str) -> (Arc<ItemMap>, ModuleId) { | |||
17 | let source_root = db.file_source_root(pos.file_id); | 17 | let source_root = db.file_source_root(pos.file_id); |
18 | let module = crate::source_binder::module_from_position(&db, pos).unwrap(); | 18 | let module = crate::source_binder::module_from_position(&db, pos).unwrap(); |
19 | let module_id = module.def_id.loc(&db).module_id; | 19 | let module_id = module.def_id.loc(&db).module_id; |
20 | (db.item_map(source_root).unwrap(), module_id) | 20 | (db.item_map(source_root), module_id) |
21 | } | 21 | } |
22 | 22 | ||
23 | fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) { | 23 | fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) { |
@@ -242,7 +242,7 @@ fn item_map_across_crates() { | |||
242 | let source_root = db.file_source_root(main_id); | 242 | let source_root = db.file_source_root(main_id); |
243 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); | 243 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); |
244 | let module_id = module.def_id.loc(&db).module_id; | 244 | let module_id = module.def_id.loc(&db).module_id; |
245 | let item_map = db.item_map(source_root).unwrap(); | 245 | let item_map = db.item_map(source_root); |
246 | 246 | ||
247 | check_module_item_map( | 247 | check_module_item_map( |
248 | &item_map, | 248 | &item_map, |
@@ -294,7 +294,7 @@ fn import_across_source_roots() { | |||
294 | 294 | ||
295 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); | 295 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); |
296 | let module_id = module.def_id.loc(&db).module_id; | 296 | let module_id = module.def_id.loc(&db).module_id; |
297 | let item_map = db.item_map(source_root).unwrap(); | 297 | let item_map = db.item_map(source_root); |
298 | 298 | ||
299 | check_module_item_map( | 299 | check_module_item_map( |
300 | &item_map, | 300 | &item_map, |
@@ -337,7 +337,7 @@ fn reexport_across_crates() { | |||
337 | let source_root = db.file_source_root(main_id); | 337 | let source_root = db.file_source_root(main_id); |
338 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); | 338 | let module = crate::source_binder::module_from_file_id(&db, main_id).unwrap(); |
339 | let module_id = module.def_id.loc(&db).module_id; | 339 | let module_id = module.def_id.loc(&db).module_id; |
340 | let item_map = db.item_map(source_root).unwrap(); | 340 | let item_map = db.item_map(source_root); |
341 | 341 | ||
342 | check_module_item_map( | 342 | check_module_item_map( |
343 | &item_map, | 343 | &item_map, |
@@ -354,7 +354,7 @@ fn check_item_map_is_not_recomputed(initial: &str, file_change: &str) { | |||
354 | let source_root = db.file_source_root(pos.file_id); | 354 | let source_root = db.file_source_root(pos.file_id); |
355 | { | 355 | { |
356 | let events = db.log_executed(|| { | 356 | let events = db.log_executed(|| { |
357 | db.item_map(source_root).unwrap(); | 357 | db.item_map(source_root); |
358 | }); | 358 | }); |
359 | assert!(format!("{:?}", events).contains("item_map")) | 359 | assert!(format!("{:?}", events).contains("item_map")) |
360 | } | 360 | } |
@@ -363,7 +363,7 @@ fn check_item_map_is_not_recomputed(initial: &str, file_change: &str) { | |||
363 | 363 | ||
364 | { | 364 | { |
365 | let events = db.log_executed(|| { | 365 | let events = db.log_executed(|| { |
366 | db.item_map(source_root).unwrap(); | 366 | db.item_map(source_root); |
367 | }); | 367 | }); |
368 | assert!( | 368 | assert!( |
369 | !format!("{:?}", events).contains("item_map"), | 369 | !format!("{:?}", events).contains("item_map"), |
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index 8f33ec707..24cb5c752 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs | |||
@@ -8,7 +8,7 @@ use ra_syntax::{ | |||
8 | AstNode, SyntaxNode, TreeArc, | 8 | AstNode, SyntaxNode, TreeArc, |
9 | ast::{self, ModuleItemOwner} | 9 | ast::{self, ModuleItemOwner} |
10 | }; | 10 | }; |
11 | use ra_db::{SourceRootId, Cancelable,}; | 11 | use ra_db::SourceRootId; |
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | SourceFileItems, SourceItemId, DefId, HirFileId, ModuleSource, | 14 | SourceFileItems, SourceItemId, DefId, HirFileId, ModuleSource, |
@@ -93,10 +93,7 @@ pub(super) fn input_module_items( | |||
93 | Arc::new(res) | 93 | Arc::new(res) |
94 | } | 94 | } |
95 | 95 | ||
96 | pub(super) fn item_map( | 96 | pub(super) fn item_map(db: &impl HirDatabase, source_root: SourceRootId) -> Arc<ItemMap> { |
97 | db: &impl HirDatabase, | ||
98 | source_root: SourceRootId, | ||
99 | ) -> Cancelable<Arc<ItemMap>> { | ||
100 | let start = Instant::now(); | 97 | let start = Instant::now(); |
101 | let module_tree = db.module_tree(source_root); | 98 | let module_tree = db.module_tree(source_root); |
102 | let input = module_tree | 99 | let input = module_tree |
@@ -105,8 +102,8 @@ pub(super) fn item_map( | |||
105 | .collect::<FxHashMap<_, _>>(); | 102 | .collect::<FxHashMap<_, _>>(); |
106 | 103 | ||
107 | let resolver = Resolver::new(db, &input, source_root, module_tree); | 104 | let resolver = Resolver::new(db, &input, source_root, module_tree); |
108 | let res = resolver.resolve()?; | 105 | let res = resolver.resolve(); |
109 | let elapsed = start.elapsed(); | 106 | let elapsed = start.elapsed(); |
110 | log::info!("item_map: {:?}", elapsed); | 107 | log::info!("item_map: {:?}", elapsed); |
111 | Ok(Arc::new(res)) | 108 | Arc::new(res) |
112 | } | 109 | } |
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 54eece165..e5f8ffc2e 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -349,7 +349,7 @@ impl Ty { | |||
349 | } | 349 | } |
350 | 350 | ||
351 | // Resolve in module (in type namespace) | 351 | // Resolve in module (in type namespace) |
352 | let resolved = if let Some(r) = module.resolve_path(db, path)?.take_types() { | 352 | let resolved = if let Some(r) = module.resolve_path(db, path).take_types() { |
353 | r | 353 | r |
354 | } else { | 354 | } else { |
355 | return Ok(Ty::Unknown); | 355 | return Ok(Ty::Unknown); |
@@ -447,8 +447,8 @@ impl fmt::Display for Ty { | |||
447 | /// function body. | 447 | /// function body. |
448 | fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable<Ty> { | 448 | fn 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, |
@@ -860,7 +860,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
860 | }; | 860 | }; |
861 | 861 | ||
862 | // resolve in module | 862 | // resolve in module |
863 | let resolved = ctry!(self.module.resolve_path(self.db, &path)?.take_values()); | 863 | let resolved = ctry!(self.module.resolve_path(self.db, &path).take_values()); |
864 | let ty = self.db.type_for_def(resolved)?; | 864 | let ty = self.db.type_for_def(resolved)?; |
865 | let ty = self.insert_type_vars(ty); | 865 | let ty = self.insert_type_vars(ty); |
866 | Ok(Some(ty)) | 866 | Ok(Some(ty)) |
@@ -872,7 +872,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
872 | } else { | 872 | } else { |
873 | return Ok((Ty::Unknown, None)); | 873 | return Ok((Ty::Unknown, None)); |
874 | }; | 874 | }; |
875 | let def_id = if let Some(def_id) = self.module.resolve_path(self.db, &path)?.take_types() { | 875 | let def_id = if let Some(def_id) = self.module.resolve_path(self.db, &path).take_types() { |
876 | def_id | 876 | def_id |
877 | } else { | 877 | } else { |
878 | return Ok((Ty::Unknown, None)); | 878 | return Ok((Ty::Unknown, None)); |
@@ -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 | ||
103 | fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Cancelable<Option<Crate>> { | 103 | fn 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 | }; |
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 207a509b3..42468681a 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -8,13 +8,13 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> C | |||
8 | (Some(path), Some(module)) => (path.clone(), module), | 8 | (Some(path), Some(module)) => (path.clone(), module), |
9 | _ => return Ok(()), | 9 | _ => return Ok(()), |
10 | }; | 10 | }; |
11 | let def_id = match module.resolve_path(ctx.db, &path)?.take_types() { | 11 | let def_id = match module.resolve_path(ctx.db, &path).take_types() { |
12 | Some(it) => it, | 12 | Some(it) => it, |
13 | None => return Ok(()), | 13 | None => return Ok(()), |
14 | }; | 14 | }; |
15 | match def_id.resolve(ctx.db) { | 15 | match def_id.resolve(ctx.db) { |
16 | hir::Def::Module(module) => { | 16 | hir::Def::Module(module) => { |
17 | let module_scope = module.scope(ctx.db)?; | 17 | let module_scope = module.scope(ctx.db); |
18 | for (name, res) in module_scope.entries() { | 18 | for (name, res) in module_scope.entries() { |
19 | CompletionItem::new(CompletionKind::Reference, name.to_string()) | 19 | CompletionItem::new(CompletionKind::Reference, name.to_string()) |
20 | .from_resolution(ctx, res) | 20 | .from_resolution(ctx, res) |
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index fdb64895e..660c7d16e 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs | |||
@@ -19,7 +19,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> | |||
19 | complete_fn(acc, &scopes, ctx.offset); | 19 | complete_fn(acc, &scopes, ctx.offset); |
20 | } | 20 | } |
21 | 21 | ||
22 | let module_scope = module.scope(ctx.db)?; | 22 | let module_scope = module.scope(ctx.db); |
23 | let (file_id, _) = module.definition_source(ctx.db); | 23 | let (file_id, _) = module.definition_source(ctx.db); |
24 | module_scope | 24 | module_scope |
25 | .entries() | 25 | .entries() |
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 5d522181b..cdd8e211d 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs | |||
@@ -85,7 +85,7 @@ pub(crate) fn reference_definition( | |||
85 | .find_map(ast::Path::cast) | 85 | .find_map(ast::Path::cast) |
86 | .and_then(hir::Path::from_ast) | 86 | .and_then(hir::Path::from_ast) |
87 | { | 87 | { |
88 | let resolved = module.resolve_path(db, &path)?; | 88 | let resolved = module.resolve_path(db, &path); |
89 | if let Some(def_id) = resolved.take_types().or(resolved.take_values()) { | 89 | if let Some(def_id) = resolved.take_types().or(resolved.take_values()) { |
90 | if let Some(target) = NavigationTarget::from_def(db, def_id.resolve(db)) { | 90 | if let Some(target) = NavigationTarget::from_def(db, def_id.resolve(db)) { |
91 | return Ok(Exact(target)); | 91 | return Ok(Exact(target)); |