aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/adt.rs23
-rw-r--r--crates/ra_hir/src/code_model_api.rs115
-rw-r--r--crates/ra_hir/src/code_model_impl/function.rs7
-rw-r--r--crates/ra_hir/src/code_model_impl/krate.rs8
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs86
-rw-r--r--crates/ra_hir/src/db.rs16
-rw-r--r--crates/ra_hir/src/expr.rs21
-rw-r--r--crates/ra_hir/src/ids.rs27
-rw-r--r--crates/ra_hir/src/impl_block.rs14
-rw-r--r--crates/ra_hir/src/nameres.rs46
-rw-r--r--crates/ra_hir/src/nameres/tests.rs12
-rw-r--r--crates/ra_hir/src/query_definitions.rs17
-rw-r--r--crates/ra_hir/src/ty.rs36
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs14
-rw-r--r--crates/ra_hir/src/ty/tests.rs2
-rw-r--r--crates/ra_ide_api/src/completion/complete_dot.rs6
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs8
-rw-r--r--crates/ra_ide_api/src/completion/complete_scope.rs6
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs2
-rw-r--r--crates/ra_ide_api/src/goto_definition.rs12
-rw-r--r--crates/ra_ide_api/src/hover.rs2
-rw-r--r--crates/ra_ide_api/src/imp.rs14
-rw-r--r--crates/ra_ide_api/src/lib.rs2
-rw-r--r--crates/ra_ide_api/src/navigation_target.rs56
-rw-r--r--crates/ra_ide_api/src/parent_module.rs2
-rw-r--r--crates/ra_ide_api/src/runnables.rs4
26 files changed, 245 insertions, 313 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index bcb705c24..57d112f74 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -19,7 +19,7 @@ impl Struct {
19 } 19 }
20 20
21 pub(crate) fn variant_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<VariantData>> { 21 pub(crate) fn variant_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<VariantData>> {
22 Ok(db.struct_data(self.def_id)?.variant_data.clone()) 22 Ok(db.struct_data(self.def_id).variant_data.clone())
23 } 23 }
24} 24}
25 25
@@ -37,16 +37,13 @@ impl StructData {
37 StructData { name, variant_data } 37 StructData { name, variant_data }
38 } 38 }
39 39
40 pub(crate) fn struct_data_query( 40 pub(crate) fn struct_data_query(db: &impl HirDatabase, def_id: DefId) -> Arc<StructData> {
41 db: &impl HirDatabase,
42 def_id: DefId,
43 ) -> Cancelable<Arc<StructData>> {
44 let def_loc = def_id.loc(db); 41 let def_loc = def_id.loc(db);
45 assert!(def_loc.kind == DefKind::Struct); 42 assert!(def_loc.kind == DefKind::Struct);
46 let syntax = db.file_item(def_loc.source_item_id); 43 let syntax = db.file_item(def_loc.source_item_id);
47 let struct_def = 44 let struct_def =
48 ast::StructDef::cast(&syntax).expect("struct def should point to StructDef node"); 45 ast::StructDef::cast(&syntax).expect("struct def should point to StructDef node");
49 Ok(Arc::new(StructData::new(struct_def))) 46 Arc::new(StructData::new(struct_def))
50 } 47 }
51} 48}
52 49
@@ -84,10 +81,7 @@ impl EnumData {
84 EnumData { name, variants } 81 EnumData { name, variants }
85 } 82 }
86 83
87 pub(crate) fn enum_data_query( 84 pub(crate) fn enum_data_query(db: &impl HirDatabase, def_id: DefId) -> Arc<EnumData> {
88 db: &impl HirDatabase,
89 def_id: DefId,
90 ) -> Cancelable<Arc<EnumData>> {
91 let def_loc = def_id.loc(db); 85 let def_loc = def_id.loc(db);
92 assert!(def_loc.kind == DefKind::Enum); 86 assert!(def_loc.kind == DefKind::Enum);
93 let syntax = db.file_item(def_loc.source_item_id); 87 let syntax = db.file_item(def_loc.source_item_id);
@@ -107,7 +101,7 @@ impl EnumData {
107 } else { 101 } else {
108 Vec::new() 102 Vec::new()
109 }; 103 };
110 Ok(Arc::new(EnumData::new(enum_def, variants))) 104 Arc::new(EnumData::new(enum_def, variants))
111 } 105 }
112} 106}
113 107
@@ -133,7 +127,7 @@ impl EnumVariantData {
133 pub(crate) fn enum_variant_data_query( 127 pub(crate) fn enum_variant_data_query(
134 db: &impl HirDatabase, 128 db: &impl HirDatabase,
135 def_id: DefId, 129 def_id: DefId,
136 ) -> Cancelable<Arc<EnumVariantData>> { 130 ) -> Arc<EnumVariantData> {
137 let def_loc = def_id.loc(db); 131 let def_loc = def_id.loc(db);
138 assert!(def_loc.kind == DefKind::EnumVariant); 132 assert!(def_loc.kind == DefKind::EnumVariant);
139 let syntax = db.file_item(def_loc.source_item_id); 133 let syntax = db.file_item(def_loc.source_item_id);
@@ -146,10 +140,7 @@ impl EnumVariantData {
146 .expect("enum variant list should have enum ancestor"); 140 .expect("enum variant list should have enum ancestor");
147 let enum_def_id = get_def_id(db, &def_loc, enum_node, DefKind::Enum); 141 let enum_def_id = get_def_id(db, &def_loc, enum_node, DefKind::Enum);
148 142
149 Ok(Arc::new(EnumVariantData::new( 143 Arc::new(EnumVariantData::new(variant_def, Enum::new(enum_def_id)))
150 variant_def,
151 Enum::new(enum_def_id),
152 )))
153 } 144 }
154} 145}
155 146
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 5db53a34f..7ccd29e2f 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 {
33 pub fn crate_id(&self) -> CrateId { 33 pub fn crate_id(&self) -> CrateId {
34 self.crate_id 34 self.crate_id
35 } 35 }
36 pub fn dependencies(&self, db: &impl HirDatabase) -> Cancelable<Vec<CrateDependency>> { 36 pub fn dependencies(&self, db: &impl HirDatabase) -> Vec<CrateDependency> {
37 Ok(self.dependencies_impl(db)) 37 self.dependencies_impl(db)
38 } 38 }
39 pub fn root_module(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> { 39 pub fn root_module(&self, db: &impl HirDatabase) -> Option<Module> {
40 self.root_module_impl(db) 40 self.root_module_impl(db)
41 } 41 }
42} 42}
@@ -78,12 +78,12 @@ pub enum Problem {
78 78
79impl Module { 79impl Module {
80 /// Name of this module. 80 /// Name of this module.
81 pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { 81 pub fn name(&self, db: &impl HirDatabase) -> Option<Name> {
82 self.name_impl(db) 82 self.name_impl(db)
83 } 83 }
84 84
85 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. 85 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
86 pub fn definition_source(&self, db: &impl HirDatabase) -> Cancelable<(FileId, ModuleSource)> { 86 pub fn definition_source(&self, db: &impl HirDatabase) -> (FileId, ModuleSource) {
87 self.definition_source_impl(db) 87 self.definition_source_impl(db)
88 } 88 }
89 89
@@ -92,19 +92,19 @@ impl Module {
92 pub fn declaration_source( 92 pub fn declaration_source(
93 &self, 93 &self,
94 db: &impl HirDatabase, 94 db: &impl HirDatabase,
95 ) -> Cancelable<Option<(FileId, TreeArc<ast::Module>)>> { 95 ) -> Option<(FileId, TreeArc<ast::Module>)> {
96 self.declaration_source_impl(db) 96 self.declaration_source_impl(db)
97 } 97 }
98 98
99 /// Returns the crate this module is part of. 99 /// Returns the crate this module is part of.
100 pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> { 100 pub fn krate(&self, db: &impl HirDatabase) -> Option<Crate> {
101 self.krate_impl(db) 101 self.krate_impl(db)
102 } 102 }
103 103
104 /// Topmost parent of this module. Every module has a `crate_root`, but some 104 /// Topmost parent of this module. Every module has a `crate_root`, but some
105 /// might be missing `krate`. This can happen if a module's file is not included 105 /// might be missing `krate`. This can happen if a module's file is not included
106 /// in the module tree of any target in Cargo.toml. 106 /// in the module tree of any target in Cargo.toml.
107 pub fn crate_root(&self, db: &impl HirDatabase) -> Cancelable<Module> { 107 pub fn crate_root(&self, db: &impl HirDatabase) -> Module {
108 self.crate_root_impl(db) 108 self.crate_root_impl(db)
109 } 109 }
110 110
@@ -114,31 +114,31 @@ impl Module {
114 } 114 }
115 115
116 /// Iterates over all child modules. 116 /// Iterates over all child modules.
117 pub fn children(&self, db: &impl HirDatabase) -> Cancelable<impl Iterator<Item = Module>> { 117 pub fn children(&self, db: &impl HirDatabase) -> impl Iterator<Item = Module> {
118 self.children_impl(db) 118 self.children_impl(db)
119 } 119 }
120 120
121 /// Finds a parent module. 121 /// Finds a parent module.
122 pub fn parent(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> { 122 pub fn parent(&self, db: &impl HirDatabase) -> Option<Module> {
123 self.parent_impl(db) 123 self.parent_impl(db)
124 } 124 }
125 125
126 pub fn path_to_root(&self, db: &impl HirDatabase) -> Cancelable<Vec<Module>> { 126 pub fn path_to_root(&self, db: &impl HirDatabase) -> Vec<Module> {
127 let mut res = vec![self.clone()]; 127 let mut res = vec![self.clone()];
128 let mut curr = self.clone(); 128 let mut curr = self.clone();
129 while let Some(next) = curr.parent(db)? { 129 while let Some(next) = curr.parent(db) {
130 res.push(next.clone()); 130 res.push(next.clone());
131 curr = next 131 curr = next
132 } 132 }
133 Ok(res) 133 res
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
@@ -175,13 +175,12 @@ impl Struct {
175 self.def_id 175 self.def_id
176 } 176 }
177 177
178 pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { 178 pub fn name(&self, db: &impl HirDatabase) -> Option<Name> {
179 Ok(db.struct_data(self.def_id)?.name.clone()) 179 db.struct_data(self.def_id).name.clone()
180 } 180 }
181 181
182 pub fn fields(&self, db: &impl HirDatabase) -> Cancelable<Vec<StructField>> { 182 pub fn fields(&self, db: &impl HirDatabase) -> Vec<StructField> {
183 let res = db 183 db.struct_data(self.def_id)
184 .struct_data(self.def_id)?
185 .variant_data 184 .variant_data
186 .fields() 185 .fields()
187 .iter() 186 .iter()
@@ -189,15 +188,11 @@ impl Struct {
189 struct_: self.clone(), 188 struct_: self.clone(),
190 name: it.name.clone(), 189 name: it.name.clone(),
191 }) 190 })
192 .collect(); 191 .collect()
193 Ok(res)
194 } 192 }
195 193
196 pub fn source( 194 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::StructDef>) {
197 &self, 195 def_id_to_ast(db, self.def_id)
198 db: &impl HirDatabase,
199 ) -> Cancelable<(HirFileId, TreeArc<ast::StructDef>)> {
200 Ok(def_id_to_ast(db, self.def_id))
201 } 196 }
202} 197}
203 198
@@ -215,16 +210,16 @@ impl Enum {
215 self.def_id 210 self.def_id
216 } 211 }
217 212
218 pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { 213 pub fn name(&self, db: &impl HirDatabase) -> Option<Name> {
219 Ok(db.enum_data(self.def_id)?.name.clone()) 214 db.enum_data(self.def_id).name.clone()
220 } 215 }
221 216
222 pub fn variants(&self, db: &impl HirDatabase) -> Cancelable<Vec<(Name, EnumVariant)>> { 217 pub fn variants(&self, db: &impl HirDatabase) -> Vec<(Name, EnumVariant)> {
223 Ok(db.enum_data(self.def_id)?.variants.clone()) 218 db.enum_data(self.def_id).variants.clone()
224 } 219 }
225 220
226 pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::EnumDef>)> { 221 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::EnumDef>) {
227 Ok(def_id_to_ast(db, self.def_id)) 222 def_id_to_ast(db, self.def_id)
228 } 223 }
229} 224}
230 225
@@ -242,23 +237,20 @@ impl EnumVariant {
242 self.def_id 237 self.def_id
243 } 238 }
244 239
245 pub fn parent_enum(&self, db: &impl HirDatabase) -> Cancelable<Enum> { 240 pub fn parent_enum(&self, db: &impl HirDatabase) -> Enum {
246 Ok(db.enum_variant_data(self.def_id)?.parent_enum.clone()) 241 db.enum_variant_data(self.def_id).parent_enum.clone()
247 } 242 }
248 243
249 pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { 244 pub fn name(&self, db: &impl HirDatabase) -> Option<Name> {
250 Ok(db.enum_variant_data(self.def_id)?.name.clone()) 245 db.enum_variant_data(self.def_id).name.clone()
251 } 246 }
252 247
253 pub fn variant_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<VariantData>> { 248 pub fn variant_data(&self, db: &impl HirDatabase) -> Arc<VariantData> {
254 Ok(db.enum_variant_data(self.def_id)?.variant_data.clone()) 249 db.enum_variant_data(self.def_id).variant_data.clone()
255 } 250 }
256 251
257 pub fn source( 252 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::EnumVariant>) {
258 &self, 253 def_id_to_ast(db, self.def_id)
259 db: &impl HirDatabase,
260 ) -> Cancelable<(HirFileId, TreeArc<ast::EnumVariant>)> {
261 Ok(def_id_to_ast(db, self.def_id))
262 } 254 }
263} 255}
264 256
@@ -305,21 +297,21 @@ impl Function {
305 self.def_id 297 self.def_id
306 } 298 }
307 299
308 pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::FnDef>)> { 300 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::FnDef>) {
309 Ok(def_id_to_ast(db, self.def_id)) 301 def_id_to_ast(db, self.def_id)
310 } 302 }
311 303
312 pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Cancelable<Arc<BodySyntaxMapping>> { 304 pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Arc<BodySyntaxMapping> {
313 db.body_syntax_mapping(self.def_id) 305 db.body_syntax_mapping(self.def_id)
314 } 306 }
315 307
316 pub fn scopes(&self, db: &impl HirDatabase) -> Cancelable<ScopesWithSyntaxMapping> { 308 pub fn scopes(&self, db: &impl HirDatabase) -> ScopesWithSyntaxMapping {
317 let scopes = db.fn_scopes(self.def_id)?; 309 let scopes = db.fn_scopes(self.def_id);
318 let syntax_mapping = db.body_syntax_mapping(self.def_id)?; 310 let syntax_mapping = db.body_syntax_mapping(self.def_id);
319 Ok(ScopesWithSyntaxMapping { 311 ScopesWithSyntaxMapping {
320 scopes, 312 scopes,
321 syntax_mapping, 313 syntax_mapping,
322 }) 314 }
323 } 315 }
324 316
325 pub fn signature(&self, db: &impl HirDatabase) -> Arc<FnSignature> { 317 pub fn signature(&self, db: &impl HirDatabase) -> Arc<FnSignature> {
@@ -341,8 +333,8 @@ impl Const {
341 Const { def_id } 333 Const { def_id }
342 } 334 }
343 335
344 pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::ConstDef>)> { 336 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) {
345 Ok(def_id_to_ast(db, self.def_id)) 337 def_id_to_ast(db, self.def_id)
346 } 338 }
347} 339}
348 340
@@ -356,11 +348,8 @@ impl Static {
356 Static { def_id } 348 Static { def_id }
357 } 349 }
358 350
359 pub fn source( 351 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) {
360 &self, 352 def_id_to_ast(db, self.def_id)
361 db: &impl HirDatabase,
362 ) -> Cancelable<(HirFileId, TreeArc<ast::StaticDef>)> {
363 Ok(def_id_to_ast(db, self.def_id))
364 } 353 }
365} 354}
366 355
@@ -374,8 +363,8 @@ impl Trait {
374 Trait { def_id } 363 Trait { def_id }
375 } 364 }
376 365
377 pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::TraitDef>)> { 366 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) {
378 Ok(def_id_to_ast(db, self.def_id)) 367 def_id_to_ast(db, self.def_id)
379 } 368 }
380} 369}
381 370
@@ -389,7 +378,7 @@ impl Type {
389 Type { def_id } 378 Type { def_id }
390 } 379 }
391 380
392 pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::TypeDef>)> { 381 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::TypeDef>) {
393 Ok(def_id_to_ast(db, self.def_id)) 382 def_id_to_ast(db, self.def_id)
394 } 383 }
395} 384}
diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs
index 8d6b7fc19..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::{
@@ -20,16 +19,16 @@ impl Function {
20 Function { def_id } 19 Function { def_id }
21 } 20 }
22 21
23 pub(crate) fn body(&self, db: &impl HirDatabase) -> Cancelable<Arc<Body>> { 22 pub(crate) fn body(&self, db: &impl HirDatabase) -> Arc<Body> {
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/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 @@
1use ra_db::{CrateId, Cancelable}; 1use ra_db::CrateId;
2 2
3use crate::{ 3use crate::{
4 HirFileId, Crate, CrateDependency, AsName, DefLoc, DefKind, Module, SourceItemId, 4 HirFileId, Crate, CrateDependency, AsName, DefLoc, DefKind, Module, SourceItemId,
@@ -20,7 +20,7 @@ impl Crate {
20 }) 20 })
21 .collect() 21 .collect()
22 } 22 }
23 pub(crate) fn root_module_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> { 23 pub(crate) fn root_module_impl(&self, db: &impl HirDatabase) -> Option<Module> {
24 let crate_graph = db.crate_graph(); 24 let crate_graph = db.crate_graph();
25 let file_id = crate_graph.crate_root(self.crate_id); 25 let file_id = crate_graph.crate_root(self.crate_id);
26 let source_root_id = db.file_source_root(file_id); 26 let source_root_id = db.file_source_root(file_id);
@@ -31,7 +31,7 @@ impl Crate {
31 file_id, 31 file_id,
32 item_id: None, 32 item_id: None,
33 }; 33 };
34 let module_id = ctry!(module_tree.find_module_by_source(source)); 34 let module_id = module_tree.find_module_by_source(source)?;
35 35
36 let def_loc = DefLoc { 36 let def_loc = DefLoc {
37 kind: DefKind::Module, 37 kind: DefKind::Module,
@@ -42,6 +42,6 @@ impl Crate {
42 let def_id = def_loc.id(db); 42 let def_id = def_loc.id(db);
43 43
44 let module = Module::new(def_id); 44 let module = Module::new(def_id);
45 Ok(Some(module)) 45 Some(module)
46 } 46 }
47} 47}
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
index 67808d282..04301ae53 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 {
30 Module::new(def_id) 30 Module::new(def_id)
31 } 31 }
32 32
33 pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { 33 pub(crate) fn name_impl(&self, db: &impl HirDatabase) -> Option<Name> {
34 let loc = self.def_id.loc(db); 34 let loc = self.def_id.loc(db);
35 let module_tree = db.module_tree(loc.source_root_id); 35 let module_tree = db.module_tree(loc.source_root_id);
36 let link = ctry!(loc.module_id.parent_link(&module_tree)); 36 let link = loc.module_id.parent_link(&module_tree)?;
37 Ok(Some(link.name(&module_tree).clone())) 37 Some(link.name(&module_tree).clone())
38 } 38 }
39 39
40 pub fn definition_source_impl( 40 pub fn definition_source_impl(&self, db: &impl HirDatabase) -> (FileId, ModuleSource) {
41 &self,
42 db: &impl HirDatabase,
43 ) -> Cancelable<(FileId, ModuleSource)> {
44 let loc = self.def_id.loc(db); 41 let loc = self.def_id.loc(db);
45 let file_id = loc.source_item_id.file_id.as_original_file(); 42 let file_id = loc.source_item_id.file_id.as_original_file();
46 let syntax_node = db.file_item(loc.source_item_id); 43 let syntax_node = db.file_item(loc.source_item_id);
@@ -50,40 +47,40 @@ impl Module {
50 let module = ast::Module::cast(&syntax_node).unwrap(); 47 let module = ast::Module::cast(&syntax_node).unwrap();
51 ModuleSource::Module(module.to_owned()) 48 ModuleSource::Module(module.to_owned())
52 }; 49 };
53 Ok((file_id, module_source)) 50 (file_id, module_source)
54 } 51 }
55 52
56 pub fn declaration_source_impl( 53 pub fn declaration_source_impl(
57 &self, 54 &self,
58 db: &impl HirDatabase, 55 db: &impl HirDatabase,
59 ) -> Cancelable<Option<(FileId, TreeArc<ast::Module>)>> { 56 ) -> Option<(FileId, TreeArc<ast::Module>)> {
60 let loc = self.def_id.loc(db); 57 let loc = self.def_id.loc(db);
61 let module_tree = db.module_tree(loc.source_root_id); 58 let module_tree = db.module_tree(loc.source_root_id);
62 let link = ctry!(loc.module_id.parent_link(&module_tree)); 59 let link = loc.module_id.parent_link(&module_tree)?;
63 let file_id = link 60 let file_id = link
64 .owner(&module_tree) 61 .owner(&module_tree)
65 .source(&module_tree) 62 .source(&module_tree)
66 .file_id 63 .file_id
67 .as_original_file(); 64 .as_original_file();
68 let src = link.source(&module_tree, db); 65 let src = link.source(&module_tree, db);
69 Ok(Some((file_id, src))) 66 Some((file_id, src))
70 } 67 }
71 68
72 pub(crate) fn krate_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> { 69 pub(crate) fn krate_impl(&self, db: &impl HirDatabase) -> Option<Crate> {
73 let root = self.crate_root(db)?; 70 let root = self.crate_root(db);
74 let loc = root.def_id.loc(db); 71 let loc = root.def_id.loc(db);
75 let file_id = loc.source_item_id.file_id.as_original_file(); 72 let file_id = loc.source_item_id.file_id.as_original_file();
76 73
77 let crate_graph = db.crate_graph(); 74 let crate_graph = db.crate_graph();
78 let crate_id = ctry!(crate_graph.crate_id_for_crate_root(file_id)); 75 let crate_id = crate_graph.crate_id_for_crate_root(file_id)?;
79 Ok(Some(Crate::new(crate_id))) 76 Some(Crate::new(crate_id))
80 } 77 }
81 78
82 pub(crate) fn crate_root_impl(&self, db: &impl HirDatabase) -> Cancelable<Module> { 79 pub(crate) fn crate_root_impl(&self, db: &impl HirDatabase) -> Module {
83 let loc = self.def_id.loc(db); 80 let loc = self.def_id.loc(db);
84 let module_tree = db.module_tree(loc.source_root_id); 81 let module_tree = db.module_tree(loc.source_root_id);
85 let module_id = loc.module_id.crate_root(&module_tree); 82 let module_id = loc.module_id.crate_root(&module_tree);
86 Ok(Module::from_module_id(db, loc.source_root_id, module_id)) 83 Module::from_module_id(db, loc.source_root_id, module_id)
87 } 84 }
88 85
89 /// Finds a child module with the specified name. 86 /// Finds a child module with the specified name.
@@ -95,7 +92,7 @@ impl Module {
95 } 92 }
96 93
97 /// Iterates over all child modules. 94 /// Iterates over all child modules.
98 pub fn children_impl(&self, db: &impl HirDatabase) -> Cancelable<impl Iterator<Item = Module>> { 95 pub fn children_impl(&self, db: &impl HirDatabase) -> impl Iterator<Item = Module> {
99 // FIXME this should be implementable without collecting into a vec, but 96 // FIXME this should be implementable without collecting into a vec, but
100 // it's kind of hard since the iterator needs to keep a reference to the 97 // it's kind of hard since the iterator needs to keep a reference to the
101 // module tree. 98 // module tree.
@@ -106,42 +103,33 @@ impl Module {
106 .children(&module_tree) 103 .children(&module_tree)
107 .map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id)) 104 .map(|(_, module_id)| Module::from_module_id(db, loc.source_root_id, module_id))
108 .collect::<Vec<_>>(); 105 .collect::<Vec<_>>();
109 Ok(children.into_iter()) 106 children.into_iter()
110 } 107 }
111 108
112 pub fn parent_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> { 109 pub fn parent_impl(&self, db: &impl HirDatabase) -> Option<Module> {
113 let loc = self.def_id.loc(db); 110 let loc = self.def_id.loc(db);
114 let module_tree = db.module_tree(loc.source_root_id); 111 let module_tree = db.module_tree(loc.source_root_id);
115 let parent_id = ctry!(loc.module_id.parent(&module_tree)); 112 let parent_id = loc.module_id.parent(&module_tree)?;
116 Ok(Some(Module::from_module_id( 113 Some(Module::from_module_id(db, loc.source_root_id, parent_id))
117 db,
118 loc.source_root_id,
119 parent_id,
120 )))
121 } 114 }
122 115
123 /// Returns a `ModuleScope`: a set of items, visible in this module. 116 /// Returns a `ModuleScope`: a set of items, visible in this module.
124 pub fn scope_impl(&self, db: &impl HirDatabase) -> Cancelable<ModuleScope> { 117 pub fn scope_impl(&self, db: &impl HirDatabase) -> ModuleScope {
125 let loc = self.def_id.loc(db); 118 let loc = self.def_id.loc(db);
126 let item_map = db.item_map(loc.source_root_id)?; 119 let item_map = db.item_map(loc.source_root_id);
127 let res = item_map.per_module[&loc.module_id].clone(); 120 item_map.per_module[&loc.module_id].clone()
128 Ok(res)
129 } 121 }
130 122
131 pub fn resolve_path_impl( 123 pub fn resolve_path_impl(&self, db: &impl HirDatabase, path: &Path) -> PerNs<DefId> {
132 &self,
133 db: &impl HirDatabase,
134 path: &Path,
135 ) -> Cancelable<PerNs<DefId>> {
136 let mut curr_per_ns = PerNs::types( 124 let mut curr_per_ns = PerNs::types(
137 match path.kind { 125 match path.kind {
138 PathKind::Crate => self.crate_root(db)?, 126 PathKind::Crate => self.crate_root(db),
139 PathKind::Self_ | PathKind::Plain => self.clone(), 127 PathKind::Self_ | PathKind::Plain => self.clone(),
140 PathKind::Super => { 128 PathKind::Super => {
141 if let Some(p) = self.parent(db)? { 129 if let Some(p) = self.parent(db) {
142 p 130 p
143 } else { 131 } else {
144 return Ok(PerNs::none()); 132 return PerNs::none();
145 } 133 }
146 } 134 }
147 } 135 }
@@ -153,39 +141,39 @@ impl Module {
153 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() {
154 r 142 r
155 } else { 143 } else {
156 return Ok(PerNs::none()); 144 return PerNs::none();
157 }; 145 };
158 let module = match curr.resolve(db)? { 146 let module = match curr.resolve(db) {
159 Def::Module(it) => it, 147 Def::Module(it) => it,
160 Def::Enum(e) => { 148 Def::Enum(e) => {
161 if segments.len() == idx + 1 { 149 if segments.len() == idx + 1 {
162 // enum variant 150 // enum variant
163 let matching_variant = 151 let matching_variant =
164 e.variants(db)?.into_iter().find(|(n, _variant)| n == name); 152 e.variants(db).into_iter().find(|(n, _variant)| n == name);
165 153
166 if let Some((_n, variant)) = matching_variant { 154 if let Some((_n, variant)) = matching_variant {
167 return Ok(PerNs::both(variant.def_id(), e.def_id())); 155 return PerNs::both(variant.def_id(), e.def_id());
168 } else { 156 } else {
169 return Ok(PerNs::none()); 157 return PerNs::none();
170 } 158 }
171 } else if segments.len() == idx { 159 } else if segments.len() == idx {
172 // enum 160 // enum
173 return Ok(PerNs::types(e.def_id())); 161 return PerNs::types(e.def_id());
174 } else { 162 } else {
175 // malformed enum? 163 // malformed enum?
176 return Ok(PerNs::none()); 164 return PerNs::none();
177 } 165 }
178 } 166 }
179 _ => return Ok(PerNs::none()), 167 _ => return PerNs::none(),
180 }; 168 };
181 let scope = module.scope(db)?; 169 let scope = module.scope(db);
182 curr_per_ns = if let Some(r) = scope.get(&name) { 170 curr_per_ns = if let Some(r) = scope.get(&name) {
183 r.def_id 171 r.def_id
184 } else { 172 } else {
185 return Ok(PerNs::none()); 173 return PerNs::none();
186 }; 174 };
187 } 175 }
188 Ok(curr_per_ns) 176 curr_per_ns
189 } 177 }
190 178
191 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 3b2498d5a..161a5e714 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -32,22 +32,22 @@ pub trait HirDatabase: SyntaxDatabase
32 use fn crate::macros::expand_macro_invocation; 32 use fn crate::macros::expand_macro_invocation;
33 } 33 }
34 34
35 fn fn_scopes(def_id: DefId) -> Cancelable<Arc<FnScopes>> { 35 fn fn_scopes(def_id: DefId) -> Arc<FnScopes> {
36 type FnScopesQuery; 36 type FnScopesQuery;
37 use fn query_definitions::fn_scopes; 37 use fn query_definitions::fn_scopes;
38 } 38 }
39 39
40 fn struct_data(def_id: DefId) -> Cancelable<Arc<StructData>> { 40 fn struct_data(def_id: DefId) -> Arc<StructData> {
41 type StructDataQuery; 41 type StructDataQuery;
42 use fn crate::adt::StructData::struct_data_query; 42 use fn crate::adt::StructData::struct_data_query;
43 } 43 }
44 44
45 fn enum_data(def_id: DefId) -> Cancelable<Arc<EnumData>> { 45 fn enum_data(def_id: DefId) -> Arc<EnumData> {
46 type EnumDataQuery; 46 type EnumDataQuery;
47 use fn crate::adt::EnumData::enum_data_query; 47 use fn crate::adt::EnumData::enum_data_query;
48 } 48 }
49 49
50 fn enum_variant_data(def_id: DefId) -> Cancelable<Arc<EnumVariantData>> { 50 fn enum_variant_data(def_id: DefId) -> Arc<EnumVariantData> {
51 type EnumVariantDataQuery; 51 type EnumVariantDataQuery;
52 use fn crate::adt::EnumVariantData::enum_variant_data_query; 52 use fn crate::adt::EnumVariantData::enum_variant_data_query;
53 } 53 }
@@ -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 }
@@ -107,12 +107,12 @@ pub trait HirDatabase: SyntaxDatabase
107 use fn crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query; 107 use fn crate::ty::method_resolution::CrateImplBlocks::impls_in_crate_query;
108 } 108 }
109 109
110 fn body_hir(def_id: DefId) -> Cancelable<Arc<crate::expr::Body>> { 110 fn body_hir(def_id: DefId) -> Arc<crate::expr::Body> {
111 type BodyHirQuery; 111 type BodyHirQuery;
112 use fn crate::expr::body_hir; 112 use fn crate::expr::body_hir;
113 } 113 }
114 114
115 fn body_syntax_mapping(def_id: DefId) -> Cancelable<Arc<crate::expr::BodySyntaxMapping>> { 115 fn body_syntax_mapping(def_id: DefId) -> Arc<crate::expr::BodySyntaxMapping> {
116 type BodySyntaxMappingQuery; 116 type BodySyntaxMappingQuery;
117 use fn crate::expr::body_syntax_mapping; 117 use fn crate::expr::body_syntax_mapping;
118 } 118 }
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index 5081466a2..4e8dc0c54 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -4,10 +4,8 @@ use std::sync::Arc;
4use rustc_hash::FxHashMap; 4use rustc_hash::FxHashMap;
5 5
6use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap}; 6use ra_arena::{Arena, RawId, impl_arena_id, map::ArenaMap};
7use ra_db::{LocalSyntaxPtr, Cancelable}; 7use ra_db::LocalSyntaxPtr;
8use ra_syntax::{ 8use ra_syntax::ast::{self, AstNode, LoopBodyOwner, ArgListOwner, NameOwner, LiteralFlavor};
9 ast::{self, AstNode, LoopBodyOwner, ArgListOwner, NameOwner, LiteralFlavor}
10};
11 9
12use crate::{Path, type_ref::{Mutability, TypeRef}, Name, HirDatabase, DefId, Def, name::AsName}; 10use crate::{Path, type_ref::{Mutability, TypeRef}, Name, HirDatabase, DefId, Def, name::AsName};
13use crate::ty::primitive::{UintTy, UncertainIntTy, UncertainFloatTy}; 11use crate::ty::primitive::{UintTy, UncertainIntTy, UncertainFloatTy};
@@ -358,8 +356,8 @@ impl Pat {
358 356
359// Queries 357// Queries
360 358
361pub(crate) fn body_hir(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<Body>> { 359pub(crate) fn body_hir(db: &impl HirDatabase, def_id: DefId) -> Arc<Body> {
362 Ok(Arc::clone(&body_syntax_mapping(db, def_id)?.body)) 360 Arc::clone(&body_syntax_mapping(db, def_id).body)
363} 361}
364 362
365struct ExprCollector { 363struct ExprCollector {
@@ -828,17 +826,14 @@ pub(crate) fn collect_fn_body_syntax(node: &ast::FnDef) -> BodySyntaxMapping {
828 collector.into_body_syntax_mapping(params, body) 826 collector.into_body_syntax_mapping(params, body)
829} 827}
830 828
831pub(crate) fn body_syntax_mapping( 829pub(crate) fn body_syntax_mapping(db: &impl HirDatabase, def_id: DefId) -> Arc<BodySyntaxMapping> {
832 db: &impl HirDatabase, 830 let def = def_id.resolve(db);
833 def_id: DefId,
834) -> Cancelable<Arc<BodySyntaxMapping>> {
835 let def = def_id.resolve(db)?;
836 831
837 let body_syntax_mapping = match def { 832 let body_syntax_mapping = match def {
838 Def::Function(f) => collect_fn_body_syntax(&f.source(db)?.1), 833 Def::Function(f) => collect_fn_body_syntax(&f.source(db).1),
839 // TODO: consts, etc. 834 // TODO: consts, etc.
840 _ => panic!("Trying to get body for item type without body"), 835 _ => panic!("Trying to get body for item type without body"),
841 }; 836 };
842 837
843 Ok(Arc::new(body_syntax_mapping)) 838 Arc::new(body_syntax_mapping)
844} 839}
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index d7cc9b4ca..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
@@ -159,9 +159,9 @@ impl DefId {
159 db.as_ref().id2loc(self) 159 db.as_ref().id2loc(self)
160 } 160 }
161 161
162 pub fn resolve(self, db: &impl HirDatabase) -> Cancelable<Def> { 162 pub fn resolve(self, db: &impl HirDatabase) -> Def {
163 let loc = self.loc(db); 163 let loc = self.loc(db);
164 let res = match loc.kind { 164 match loc.kind {
165 DefKind::Module => { 165 DefKind::Module => {
166 let module = Module::from_module_id(db, loc.source_root_id, loc.module_id); 166 let module = Module::from_module_id(db, loc.source_root_id, loc.module_id);
167 Def::Module(module) 167 Def::Module(module)
@@ -195,8 +195,7 @@ impl DefId {
195 195
196 DefKind::StructCtor => Def::Item, 196 DefKind::StructCtor => Def::Item,
197 DefKind::Item => Def::Item, 197 DefKind::Item => Def::Item,
198 }; 198 }
199 Ok(res)
200 } 199 }
201 200
202 pub(crate) fn source(self, db: &impl HirDatabase) -> (HirFileId, TreeArc<SyntaxNode>) { 201 pub(crate) fn source(self, db: &impl HirDatabase) -> (HirFileId, TreeArc<SyntaxNode>) {
@@ -206,25 +205,21 @@ impl DefId {
206 } 205 }
207 206
208 /// 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.
209 pub fn module(self, db: &impl HirDatabase) -> Cancelable<Module> { 208 pub fn module(self, db: &impl HirDatabase) -> Module {
210 let loc = self.loc(db); 209 let loc = self.loc(db);
211 Ok(Module::from_module_id( 210 Module::from_module_id(db, loc.source_root_id, loc.module_id)
212 db,
213 loc.source_root_id,
214 loc.module_id,
215 ))
216 } 211 }
217 212
218 /// Returns the containing crate. 213 /// Returns the containing crate.
219 pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> { 214 pub fn krate(&self, db: &impl HirDatabase) -> Option<Crate> {
220 Ok(self.module(db)?.krate(db)?) 215 self.module(db).krate(db)
221 } 216 }
222 217
223 /// Returns the containing impl block, if this is an impl item. 218 /// Returns the containing impl block, if this is an impl item.
224 pub fn impl_block(self, db: &impl HirDatabase) -> Cancelable<Option<ImplBlock>> { 219 pub fn impl_block(self, db: &impl HirDatabase) -> Option<ImplBlock> {
225 let loc = self.loc(db); 220 let loc = self.loc(db);
226 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);
227 Ok(ImplBlock::containing(module_impls, self)) 222 ImplBlock::containing(module_impls, self)
228 } 223 }
229} 224}
230 225
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index c9a9fb99f..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,8 +166,8 @@ 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(),
173 ModuleSource::Module(node) => node 173 ModuleSource::Module(node) => node
@@ -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 edb3b1e64..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};
25use ra_db::{SourceRootId, Cancelable, FileId}; 25use ra_db::{SourceRootId, FileId};
26 26
27use crate::{ 27use 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
@@ -353,8 +349,8 @@ where
353 if let Some(crate_id) = crate_graph.crate_id_for_crate_root(file_id.as_original_file()) 349 if let Some(crate_id) = crate_graph.crate_id_for_crate_root(file_id.as_original_file())
354 { 350 {
355 let krate = Crate::new(crate_id); 351 let krate = Crate::new(crate_id);
356 for dep in krate.dependencies(self.db)? { 352 for dep in krate.dependencies(self.db) {
357 if let Some(module) = dep.krate.root_module(self.db)? { 353 if let Some(module) = dep.krate.root_module(self.db) {
358 let def_id = module.def_id; 354 let def_id = module.def_id;
359 self.add_module_item( 355 self.add_module_item(
360 &mut module_items, 356 &mut module_items,
@@ -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
23fn check_module_item_map(map: &ItemMap, module_id: ModuleId, expected: &str) { 23fn 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 7ff942f6a..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};
11use ra_db::{SourceRootId, Cancelable,}; 11use ra_db::SourceRootId;
12 12
13use crate::{ 13use crate::{
14 SourceFileItems, SourceItemId, DefId, HirFileId, ModuleSource, 14 SourceFileItems, SourceItemId, DefId, HirFileId, ModuleSource,
@@ -18,10 +18,10 @@ use crate::{
18 nameres::{InputModuleItems, ItemMap, Resolver}, 18 nameres::{InputModuleItems, ItemMap, Resolver},
19}; 19};
20 20
21pub(super) fn fn_scopes(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<FnScopes>> { 21pub(super) fn fn_scopes(db: &impl HirDatabase, def_id: DefId) -> Arc<FnScopes> {
22 let body = db.body_hir(def_id)?; 22 let body = db.body_hir(def_id);
23 let res = FnScopes::new(body); 23 let res = FnScopes::new(body);
24 Ok(Arc::new(res)) 24 Arc::new(res)
25} 25}
26 26
27pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc<SourceFileItems> { 27pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc<SourceFileItems> {
@@ -93,10 +93,7 @@ pub(super) fn input_module_items(
93 Arc::new(res) 93 Arc::new(res)
94} 94}
95 95
96pub(super) fn item_map( 96pub(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 03787bd89..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.
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()
@@ -463,25 +463,25 @@ fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable<Ty> {
463fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Cancelable<Ty> { 463fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Cancelable<Ty> {
464 Ok(Ty::Adt { 464 Ok(Ty::Adt {
465 def_id: s.def_id(), 465 def_id: s.def_id(),
466 name: s.name(db)?.unwrap_or_else(Name::missing), 466 name: s.name(db).unwrap_or_else(Name::missing),
467 }) 467 })
468} 468}
469 469
470pub(crate) fn type_for_enum(db: &impl HirDatabase, s: Enum) -> Cancelable<Ty> { 470pub(crate) fn type_for_enum(db: &impl HirDatabase, s: Enum) -> Cancelable<Ty> {
471 Ok(Ty::Adt { 471 Ok(Ty::Adt {
472 def_id: s.def_id(), 472 def_id: s.def_id(),
473 name: s.name(db)?.unwrap_or_else(Name::missing), 473 name: s.name(db).unwrap_or_else(Name::missing),
474 }) 474 })
475} 475}
476 476
477pub(crate) fn type_for_enum_variant(db: &impl HirDatabase, ev: EnumVariant) -> Cancelable<Ty> { 477pub(crate) fn type_for_enum_variant(db: &impl HirDatabase, ev: EnumVariant) -> Cancelable<Ty> {
478 let enum_parent = ev.parent_enum(db)?; 478 let enum_parent = ev.parent_enum(db);
479 479
480 type_for_enum(db, enum_parent) 480 type_for_enum(db, enum_parent)
481} 481}
482 482
483pub(super) fn type_for_def(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Ty> { 483pub(super) fn type_for_def(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Ty> {
484 let def = def_id.resolve(db)?; 484 let def = def_id.resolve(db);
485 match def { 485 match def {
486 Def::Module(..) => { 486 Def::Module(..) => {
487 log::debug!("trying to get type for module {:?}", def_id); 487 log::debug!("trying to get type for module {:?}", def_id);
@@ -507,18 +507,18 @@ pub(super) fn type_for_field(
507 def_id: DefId, 507 def_id: DefId,
508 field: Name, 508 field: Name,
509) -> Cancelable<Option<Ty>> { 509) -> Cancelable<Option<Ty>> {
510 let def = def_id.resolve(db)?; 510 let def = def_id.resolve(db);
511 let variant_data = match def { 511 let variant_data = match def {
512 Def::Struct(s) => s.variant_data(db)?, 512 Def::Struct(s) => s.variant_data(db)?,
513 Def::EnumVariant(ev) => ev.variant_data(db)?, 513 Def::EnumVariant(ev) => ev.variant_data(db),
514 // TODO: unions 514 // TODO: unions
515 _ => panic!( 515 _ => panic!(
516 "trying to get type for field in non-struct/variant {:?}", 516 "trying to get type for field in non-struct/variant {:?}",
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,12 +872,12 @@ 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));
879 }; 879 };
880 Ok(match def_id.resolve(self.db)? { 880 Ok(match def_id.resolve(self.db) {
881 Def::Struct(s) => { 881 Def::Struct(s) => {
882 let ty = type_for_struct(self.db, s)?; 882 let ty = type_for_struct(self.db, s)?;
883 (ty, Some(def_id)) 883 (ty, Some(def_id))
@@ -1205,10 +1205,10 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1205pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> { 1205pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> {
1206 db.check_canceled(); 1206 db.check_canceled();
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 7c3839388..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);
@@ -75,7 +75,7 @@ impl CrateImplBlocks {
75 } 75 }
76 } 76 }
77 77
78 for child in module.children(db)? { 78 for child in module.children(db) {
79 self.collect_recursive(db, child)?; 79 self.collect_recursive(db, child)?;
80 } 80 }
81 81
@@ -93,17 +93,17 @@ impl CrateImplBlocks {
93 source_root_id, 93 source_root_id,
94 impls: FxHashMap::default(), 94 impls: FxHashMap::default(),
95 }; 95 };
96 if let Some(module) = krate.root_module(db)? { 96 if let Some(module) = krate.root_module(db) {
97 crate_impl_blocks.collect_recursive(db, module)?; 97 crate_impl_blocks.collect_recursive(db, module)?;
98 } 98 }
99 Ok(Arc::new(crate_impl_blocks)) 99 Ok(Arc::new(crate_impl_blocks))
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 };
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index b81d91e80..b44ac9987 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -322,7 +322,7 @@ fn infer(content: &str) -> String {
322 { 322 {
323 let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap(); 323 let func = source_binder::function_from_source(&db, file_id, fn_def).unwrap();
324 let inference_result = func.infer(&db).unwrap(); 324 let inference_result = func.infer(&db).unwrap();
325 let body_syntax_mapping = func.body_syntax_mapping(&db).unwrap(); 325 let body_syntax_mapping = func.body_syntax_mapping(&db);
326 let mut types = Vec::new(); 326 let mut types = Vec::new();
327 for (pat, ty) in inference_result.type_of_pat.iter() { 327 for (pat, ty) in inference_result.type_of_pat.iter() {
328 let syntax_ptr = match body_syntax_mapping.pat_syntax(pat) { 328 let syntax_ptr = match body_syntax_mapping.pat_syntax(pat) {
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs
index 37985b398..cb86ba9a3 100644
--- a/crates/ra_ide_api/src/completion/complete_dot.rs
+++ b/crates/ra_ide_api/src/completion/complete_dot.rs
@@ -10,7 +10,7 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Ca
10 _ => return Ok(()), 10 _ => return Ok(()),
11 }; 11 };
12 let infer_result = function.infer(ctx.db)?; 12 let infer_result = function.infer(ctx.db)?;
13 let syntax_mapping = function.body_syntax_mapping(ctx.db)?; 13 let syntax_mapping = function.body_syntax_mapping(ctx.db);
14 let expr = match syntax_mapping.node_expr(receiver) { 14 let expr = match syntax_mapping.node_expr(receiver) {
15 Some(expr) => expr, 15 Some(expr) => expr,
16 None => return Ok(()), 16 None => return Ok(()),
@@ -27,9 +27,9 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty)
27 for receiver in receiver.autoderef(ctx.db) { 27 for receiver in receiver.autoderef(ctx.db) {
28 match receiver { 28 match receiver {
29 Ty::Adt { def_id, .. } => { 29 Ty::Adt { def_id, .. } => {
30 match def_id.resolve(ctx.db)? { 30 match def_id.resolve(ctx.db) {
31 Def::Struct(s) => { 31 Def::Struct(s) => {
32 for field in s.fields(ctx.db)? { 32 for field in s.fields(ctx.db) {
33 CompletionItem::new( 33 CompletionItem::new(
34 CompletionKind::Reference, 34 CompletionKind::Reference,
35 field.name().to_string(), 35 field.name().to_string(),
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs
index a25ad3f13..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)
@@ -22,7 +22,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> C
22 } 22 }
23 } 23 }
24 hir::Def::Enum(e) => { 24 hir::Def::Enum(e) => {
25 e.variants(ctx.db)? 25 e.variants(ctx.db)
26 .into_iter() 26 .into_iter()
27 .for_each(|(variant_name, _variant)| { 27 .for_each(|(variant_name, _variant)| {
28 CompletionItem::new(CompletionKind::Reference, variant_name.to_string()) 28 CompletionItem::new(CompletionKind::Reference, variant_name.to_string())
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs
index 770a0fdf2..660c7d16e 100644
--- a/crates/ra_ide_api/src/completion/complete_scope.rs
+++ b/crates/ra_ide_api/src/completion/complete_scope.rs
@@ -15,12 +15,12 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) ->
15 None => return Ok(()), 15 None => return Ok(()),
16 }; 16 };
17 if let Some(function) = &ctx.function { 17 if let Some(function) = &ctx.function {
18 let scopes = function.scopes(ctx.db)?; 18 let scopes = function.scopes(ctx.db);
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()
26 .filter(|(_name, res)| { 26 .filter(|(_name, res)| {
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs
index b75d65de3..11d00f78c 100644
--- a/crates/ra_ide_api/src/completion/completion_item.rs
+++ b/crates/ra_ide_api/src/completion/completion_item.rs
@@ -144,7 +144,7 @@ impl Builder {
144 ctx: &CompletionContext, 144 ctx: &CompletionContext,
145 resolution: &hir::Resolution, 145 resolution: &hir::Resolution,
146 ) -> Builder { 146 ) -> Builder {
147 let resolved = resolution.def_id.and_then(|d| d.resolve(ctx.db).ok()); 147 let resolved = resolution.def_id.map(|d| d.resolve(ctx.db));
148 let kind = match resolved { 148 let kind = match resolved {
149 PerNs { 149 PerNs {
150 types: Some(hir::Def::Module(..)), 150 types: Some(hir::Def::Module(..)),
diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs
index 591f36cce..cdd8e211d 100644
--- a/crates/ra_ide_api/src/goto_definition.rs
+++ b/crates/ra_ide_api/src/goto_definition.rs
@@ -50,7 +50,7 @@ pub(crate) fn reference_definition(
50 if let Some(function) = 50 if let Some(function) =
51 hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax()) 51 hir::source_binder::function_from_child_node(db, file_id, name_ref.syntax())
52 { 52 {
53 let scope = function.scopes(db)?; 53 let scope = function.scopes(db);
54 // First try to resolve the symbol locally 54 // First try to resolve the symbol locally
55 if let Some(entry) = scope.resolve_local_name(name_ref) { 55 if let Some(entry) = scope.resolve_local_name(name_ref) {
56 let nav = NavigationTarget::from_scope_entry(file_id, &entry); 56 let nav = NavigationTarget::from_scope_entry(file_id, &entry);
@@ -64,13 +64,13 @@ pub(crate) fn reference_definition(
64 .and_then(ast::MethodCallExpr::cast) 64 .and_then(ast::MethodCallExpr::cast)
65 { 65 {
66 let infer_result = function.infer(db)?; 66 let infer_result = function.infer(db)?;
67 let syntax_mapping = function.body_syntax_mapping(db)?; 67 let syntax_mapping = function.body_syntax_mapping(db);
68 let expr = ast::Expr::cast(method_call.syntax()).unwrap(); 68 let expr = ast::Expr::cast(method_call.syntax()).unwrap();
69 if let Some(def_id) = syntax_mapping 69 if let Some(def_id) = syntax_mapping
70 .node_expr(expr) 70 .node_expr(expr)
71 .and_then(|it| infer_result.method_resolution(it)) 71 .and_then(|it| infer_result.method_resolution(it))
72 { 72 {
73 if let Some(target) = NavigationTarget::from_def(db, def_id.resolve(db)?)? { 73 if let Some(target) = NavigationTarget::from_def(db, def_id.resolve(db)) {
74 return Ok(Exact(target)); 74 return Ok(Exact(target));
75 } 75 }
76 }; 76 };
@@ -85,9 +85,9 @@ 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));
92 } 92 }
93 } 93 }
@@ -112,7 +112,7 @@ fn name_definition(
112 if let Some(child_module) = 112 if let Some(child_module) =
113 hir::source_binder::module_from_declaration(db, file_id, module) 113 hir::source_binder::module_from_declaration(db, file_id, module)
114 { 114 {
115 let nav = NavigationTarget::from_module(db, child_module)?; 115 let nav = NavigationTarget::from_module(db, child_module);
116 return Ok(Some(vec![nav])); 116 return Ok(Some(vec![nav]));
117 } 117 }
118 } 118 }
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index 26f3ced70..0e9c48421 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -74,7 +74,7 @@ pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Cancelable<Option
74 parent_fn 74 parent_fn
75 )); 75 ));
76 let infer = function.infer(db)?; 76 let infer = function.infer(db)?;
77 let syntax_mapping = function.body_syntax_mapping(db)?; 77 let syntax_mapping = function.body_syntax_mapping(db);
78 if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) { 78 if let Some(expr) = ast::Expr::cast(node).and_then(|e| syntax_mapping.node_expr(e)) {
79 Ok(Some(infer[expr].to_string())) 79 Ok(Some(infer[expr].to_string()))
80 } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| syntax_mapping.node_pat(p)) { 80 } else if let Some(pat) = ast::Pat::cast(node).and_then(|p| syntax_mapping.node_pat(p)) {
diff --git a/crates/ra_ide_api/src/imp.rs b/crates/ra_ide_api/src/imp.rs
index 76cb312dd..8b2cd6e27 100644
--- a/crates/ra_ide_api/src/imp.rs
+++ b/crates/ra_ide_api/src/imp.rs
@@ -99,16 +99,16 @@ impl db::RootDatabase {
99 99
100impl db::RootDatabase { 100impl db::RootDatabase {
101 /// Returns `Vec` for the same reason as `parent_module` 101 /// Returns `Vec` for the same reason as `parent_module`
102 pub(crate) fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { 102 pub(crate) fn crate_for(&self, file_id: FileId) -> Vec<CrateId> {
103 let module = match source_binder::module_from_file_id(self, file_id) { 103 let module = match source_binder::module_from_file_id(self, file_id) {
104 Some(it) => it, 104 Some(it) => it,
105 None => return Ok(Vec::new()), 105 None => return Vec::new(),
106 }; 106 };
107 let krate = match module.krate(self)? { 107 let krate = match module.krate(self) {
108 Some(it) => it, 108 Some(it) => it,
109 None => return Ok(Vec::new()), 109 None => return Vec::new(),
110 }; 110 };
111 Ok(vec![krate.crate_id()]) 111 vec![krate.crate_id()]
112 } 112 }
113 pub(crate) fn find_all_refs( 113 pub(crate) fn find_all_refs(
114 &self, 114 &self,
@@ -128,7 +128,7 @@ impl db::RootDatabase {
128 .collect::<Vec<_>>(); 128 .collect::<Vec<_>>();
129 ret.extend( 129 ret.extend(
130 descr 130 descr
131 .scopes(self)? 131 .scopes(self)
132 .find_all_refs(binding) 132 .find_all_refs(binding)
133 .into_iter() 133 .into_iter()
134 .map(|ref_desc| (position.file_id, ref_desc.range)), 134 .map(|ref_desc| (position.file_id, ref_desc.range)),
@@ -156,7 +156,7 @@ impl db::RootDatabase {
156 position.file_id, 156 position.file_id,
157 name_ref.syntax(), 157 name_ref.syntax(),
158 )); 158 ));
159 let scope = descr.scopes(db)?; 159 let scope = descr.scopes(db);
160 let resolved = ctry!(scope.resolve_local_name(name_ref)); 160 let resolved = ctry!(scope.resolve_local_name(name_ref));
161 let resolved = resolved.ptr().resolve(source_file); 161 let resolved = resolved.ptr().resolve(source_file);
162 let binding = ctry!(find_node_at_offset::<ast::BindPat>( 162 let binding = ctry!(find_node_at_offset::<ast::BindPat>(
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index e0b8410d1..0f690fc84 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -419,7 +419,7 @@ impl Analysis {
419 419
420 /// Returns crates this file belongs too. 420 /// Returns crates this file belongs too.
421 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> { 421 pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
422 self.with_db(|db| db.crate_for(file_id))? 422 self.with_db(|db| db.crate_for(file_id))
423 } 423 }
424 424
425 /// Returns the root file of the given crate. 425 /// Returns the root file of the given crate.
diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs
index 230d0f67a..21c15c0c0 100644
--- a/crates/ra_ide_api/src/navigation_target.rs
+++ b/crates/ra_ide_api/src/navigation_target.rs
@@ -1,4 +1,4 @@
1use ra_db::{FileId, Cancelable}; 1use ra_db::FileId;
2use ra_syntax::{ 2use ra_syntax::{
3 SyntaxNode, AstNode, SmolStr, TextRange, ast, 3 SyntaxNode, AstNode, SmolStr, TextRange, ast,
4 SyntaxKind::{self, NAME}, 4 SyntaxKind::{self, NAME},
@@ -69,84 +69,72 @@ impl NavigationTarget {
69 } 69 }
70 } 70 }
71 71
72 pub(crate) fn from_module( 72 pub(crate) fn from_module(db: &RootDatabase, module: hir::Module) -> NavigationTarget {
73 db: &RootDatabase, 73 let (file_id, source) = module.definition_source(db);
74 module: hir::Module,
75 ) -> Cancelable<NavigationTarget> {
76 let (file_id, source) = module.definition_source(db)?;
77 let name = module 74 let name = module
78 .name(db)? 75 .name(db)
79 .map(|it| it.to_string().into()) 76 .map(|it| it.to_string().into())
80 .unwrap_or_default(); 77 .unwrap_or_default();
81 let res = match source { 78 match source {
82 ModuleSource::SourceFile(node) => { 79 ModuleSource::SourceFile(node) => {
83 NavigationTarget::from_syntax(file_id, name, None, node.syntax()) 80 NavigationTarget::from_syntax(file_id, name, None, node.syntax())
84 } 81 }
85 ModuleSource::Module(node) => { 82 ModuleSource::Module(node) => {
86 NavigationTarget::from_syntax(file_id, name, None, node.syntax()) 83 NavigationTarget::from_syntax(file_id, name, None, node.syntax())
87 } 84 }
88 }; 85 }
89 Ok(res)
90 } 86 }
91 87
92 pub(crate) fn from_module_to_decl( 88 pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget {
93 db: &RootDatabase,
94 module: hir::Module,
95 ) -> Cancelable<NavigationTarget> {
96 let name = module 89 let name = module
97 .name(db)? 90 .name(db)
98 .map(|it| it.to_string().into()) 91 .map(|it| it.to_string().into())
99 .unwrap_or_default(); 92 .unwrap_or_default();
100 if let Some((file_id, source)) = module.declaration_source(db)? { 93 if let Some((file_id, source)) = module.declaration_source(db) {
101 return Ok(NavigationTarget::from_syntax( 94 return NavigationTarget::from_syntax(file_id, name, None, source.syntax());
102 file_id,
103 name,
104 None,
105 source.syntax(),
106 ));
107 } 95 }
108 NavigationTarget::from_module(db, module) 96 NavigationTarget::from_module(db, module)
109 } 97 }
110 98
111 // TODO once Def::Item is gone, this should be able to always return a NavigationTarget 99 // TODO once Def::Item is gone, this should be able to always return a NavigationTarget
112 pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Cancelable<Option<NavigationTarget>> { 100 pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Option<NavigationTarget> {
113 let res = match def { 101 let res = match def {
114 Def::Struct(s) => { 102 Def::Struct(s) => {
115 let (file_id, node) = s.source(db)?; 103 let (file_id, node) = s.source(db);
116 NavigationTarget::from_named(file_id.original_file(db), &*node) 104 NavigationTarget::from_named(file_id.original_file(db), &*node)
117 } 105 }
118 Def::Enum(e) => { 106 Def::Enum(e) => {
119 let (file_id, node) = e.source(db)?; 107 let (file_id, node) = e.source(db);
120 NavigationTarget::from_named(file_id.original_file(db), &*node) 108 NavigationTarget::from_named(file_id.original_file(db), &*node)
121 } 109 }
122 Def::EnumVariant(ev) => { 110 Def::EnumVariant(ev) => {
123 let (file_id, node) = ev.source(db)?; 111 let (file_id, node) = ev.source(db);
124 NavigationTarget::from_named(file_id.original_file(db), &*node) 112 NavigationTarget::from_named(file_id.original_file(db), &*node)
125 } 113 }
126 Def::Function(f) => { 114 Def::Function(f) => {
127 let (file_id, node) = f.source(db)?; 115 let (file_id, node) = f.source(db);
128 NavigationTarget::from_named(file_id.original_file(db), &*node) 116 NavigationTarget::from_named(file_id.original_file(db), &*node)
129 } 117 }
130 Def::Trait(f) => { 118 Def::Trait(f) => {
131 let (file_id, node) = f.source(db)?; 119 let (file_id, node) = f.source(db);
132 NavigationTarget::from_named(file_id.original_file(db), &*node) 120 NavigationTarget::from_named(file_id.original_file(db), &*node)
133 } 121 }
134 Def::Type(f) => { 122 Def::Type(f) => {
135 let (file_id, node) = f.source(db)?; 123 let (file_id, node) = f.source(db);
136 NavigationTarget::from_named(file_id.original_file(db), &*node) 124 NavigationTarget::from_named(file_id.original_file(db), &*node)
137 } 125 }
138 Def::Static(f) => { 126 Def::Static(f) => {
139 let (file_id, node) = f.source(db)?; 127 let (file_id, node) = f.source(db);
140 NavigationTarget::from_named(file_id.original_file(db), &*node) 128 NavigationTarget::from_named(file_id.original_file(db), &*node)
141 } 129 }
142 Def::Const(f) => { 130 Def::Const(f) => {
143 let (file_id, node) = f.source(db)?; 131 let (file_id, node) = f.source(db);
144 NavigationTarget::from_named(file_id.original_file(db), &*node) 132 NavigationTarget::from_named(file_id.original_file(db), &*node)
145 } 133 }
146 Def::Module(m) => NavigationTarget::from_module(db, m)?, 134 Def::Module(m) => NavigationTarget::from_module(db, m),
147 Def::Item => return Ok(None), 135 Def::Item => return None,
148 }; 136 };
149 Ok(Some(res)) 137 Some(res)
150 } 138 }
151 139
152 #[cfg(test)] 140 #[cfg(test)]
diff --git a/crates/ra_ide_api/src/parent_module.rs b/crates/ra_ide_api/src/parent_module.rs
index 451304739..379b3f3a4 100644
--- a/crates/ra_ide_api/src/parent_module.rs
+++ b/crates/ra_ide_api/src/parent_module.rs
@@ -12,7 +12,7 @@ pub(crate) fn parent_module(
12 None => return Ok(Vec::new()), 12 None => return Ok(Vec::new()),
13 Some(it) => it, 13 Some(it) => it,
14 }; 14 };
15 let nav = NavigationTarget::from_module_to_decl(db, module)?; 15 let nav = NavigationTarget::from_module_to_decl(db, module);
16 Ok(vec![nav]) 16 Ok(vec![nav])
17} 17}
18 18
diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs
index 9fa0f79a6..a3207fdd2 100644
--- a/crates/ra_ide_api/src/runnables.rs
+++ b/crates/ra_ide_api/src/runnables.rs
@@ -80,11 +80,9 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: &ast::Module) -> Opt
80 // FIXME: thread cancellation instead of `.ok`ing 80 // FIXME: thread cancellation instead of `.ok`ing
81 let path = module 81 let path = module
82 .path_to_root(db) 82 .path_to_root(db)
83 .ok()?
84 .into_iter() 83 .into_iter()
85 .rev() 84 .rev()
86 .filter_map(|it| it.name(db).ok()) 85 .filter_map(|it| it.name(db))
87 .filter_map(|it| it)
88 .join("::"); 86 .join("::");
89 Some(Runnable { 87 Some(Runnable {
90 range, 88 range,