aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/adt.rs19
-rw-r--r--crates/ra_hir/src/code_model_api.rs94
-rw-r--r--crates/ra_hir/src/code_model_impl/function.rs7
-rw-r--r--crates/ra_hir/src/code_model_impl/konst.rs6
-rw-r--r--crates/ra_hir/src/code_model_impl/krate.rs9
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs15
-rw-r--r--crates/ra_hir/src/db.rs6
-rw-r--r--crates/ra_hir/src/expr.rs14
-rw-r--r--crates/ra_hir/src/expr/scope.rs4
-rw-r--r--crates/ra_hir/src/generics.rs6
-rw-r--r--crates/ra_hir/src/ids.rs28
-rw-r--r--crates/ra_hir/src/impl_block.rs31
-rw-r--r--crates/ra_hir/src/lib.rs2
-rw-r--r--crates/ra_hir/src/mock.rs6
-rw-r--r--crates/ra_hir/src/nameres.rs17
-rw-r--r--crates/ra_hir/src/nameres/collector.rs13
-rw-r--r--crates/ra_hir/src/nameres/raw.rs9
-rw-r--r--crates/ra_hir/src/path.rs6
-rw-r--r--crates/ra_hir/src/resolve.rs4
-rw-r--r--crates/ra_hir/src/source_binder.rs6
-rw-r--r--crates/ra_hir/src/ty/autoderef.rs2
-rw-r--r--crates/ra_hir/src/ty/infer.rs50
-rw-r--r--crates/ra_hir/src/ty/lower.rs6
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs2
-rw-r--r--crates/ra_hir/src/ty/tests.rs23
-rw-r--r--crates/ra_hir/src/type_alias.rs7
26 files changed, 182 insertions, 210 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index 325f1d7b6..78ea8976b 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -12,7 +12,7 @@ use ra_syntax::{
12use crate::{ 12use crate::{
13 Name, AsName, Struct, Enum, EnumVariant, Crate, 13 Name, AsName, Struct, Enum, EnumVariant, Crate,
14 HirDatabase, HirFileId, StructField, FieldSource, 14 HirDatabase, HirFileId, StructField, FieldSource,
15 type_ref::TypeRef, PersistentHirDatabase, 15 type_ref::TypeRef, DefDatabase,
16}; 16};
17 17
18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
@@ -33,7 +33,7 @@ impl AdtDef {
33} 33}
34 34
35impl Struct { 35impl Struct {
36 pub(crate) fn variant_data(&self, db: &impl PersistentHirDatabase) -> Arc<VariantData> { 36 pub(crate) fn variant_data(&self, db: &impl DefDatabase) -> Arc<VariantData> {
37 db.struct_data((*self).into()).variant_data.clone() 37 db.struct_data((*self).into()).variant_data.clone()
38 } 38 }
39} 39}
@@ -52,10 +52,7 @@ impl StructData {
52 StructData { name, variant_data } 52 StructData { name, variant_data }
53 } 53 }
54 54
55 pub(crate) fn struct_data_query( 55 pub(crate) fn struct_data_query(db: &impl DefDatabase, struct_: Struct) -> Arc<StructData> {
56 db: &impl PersistentHirDatabase,
57 struct_: Struct,
58 ) -> Arc<StructData> {
59 let (_, struct_def) = struct_.source(db); 56 let (_, struct_def) = struct_.source(db);
60 Arc::new(StructData::new(&*struct_def)) 57 Arc::new(StructData::new(&*struct_def))
61 } 58 }
@@ -68,7 +65,7 @@ fn variants(enum_def: &ast::EnumDef) -> impl Iterator<Item = &ast::EnumVariant>
68impl EnumVariant { 65impl EnumVariant {
69 pub(crate) fn source_impl( 66 pub(crate) fn source_impl(
70 &self, 67 &self,
71 db: &impl PersistentHirDatabase, 68 db: &impl DefDatabase,
72 ) -> (HirFileId, TreeArc<ast::EnumVariant>) { 69 ) -> (HirFileId, TreeArc<ast::EnumVariant>) {
73 let (file_id, enum_def) = self.parent.source(db); 70 let (file_id, enum_def) = self.parent.source(db);
74 let var = variants(&*enum_def) 71 let var = variants(&*enum_def)
@@ -79,7 +76,7 @@ impl EnumVariant {
79 .to_owned(); 76 .to_owned();
80 (file_id, var) 77 (file_id, var)
81 } 78 }
82 pub(crate) fn variant_data(&self, db: &impl PersistentHirDatabase) -> Arc<VariantData> { 79 pub(crate) fn variant_data(&self, db: &impl DefDatabase) -> Arc<VariantData> {
83 db.enum_data(self.parent).variants[self.id].variant_data.clone() 80 db.enum_data(self.parent).variants[self.id].variant_data.clone()
84 } 81 }
85} 82}
@@ -91,7 +88,7 @@ pub struct EnumData {
91} 88}
92 89
93impl EnumData { 90impl EnumData {
94 pub(crate) fn enum_data_query(db: &impl PersistentHirDatabase, e: Enum) -> Arc<EnumData> { 91 pub(crate) fn enum_data_query(db: &impl DefDatabase, e: Enum) -> Arc<EnumData> {
95 let (_file_id, enum_def) = e.source(db); 92 let (_file_id, enum_def) = e.source(db);
96 let name = enum_def.name().map(|n| n.as_name()); 93 let name = enum_def.name().map(|n| n.as_name());
97 let variants = variants(&*enum_def) 94 let variants = variants(&*enum_def)
@@ -189,7 +186,7 @@ impl VariantDef {
189 VariantDef::EnumVariant(it) => it.field(db, name), 186 VariantDef::EnumVariant(it) => it.field(db, name),
190 } 187 }
191 } 188 }
192 pub(crate) fn variant_data(self, db: &impl PersistentHirDatabase) -> Arc<VariantData> { 189 pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> {
193 match self { 190 match self {
194 VariantDef::Struct(it) => it.variant_data(db), 191 VariantDef::Struct(it) => it.variant_data(db),
195 VariantDef::EnumVariant(it) => it.variant_data(db), 192 VariantDef::EnumVariant(it) => it.variant_data(db),
@@ -198,7 +195,7 @@ impl VariantDef {
198} 195}
199 196
200impl StructField { 197impl StructField {
201 pub(crate) fn source_impl(&self, db: &impl PersistentHirDatabase) -> (HirFileId, FieldSource) { 198 pub(crate) fn source_impl(&self, db: &impl DefDatabase) -> (HirFileId, FieldSource) {
202 let var_data = self.parent.variant_data(db); 199 let var_data = self.parent.variant_data(db);
203 let fields = var_data.fields().unwrap(); 200 let fields = var_data.fields().unwrap();
204 let ss; 201 let ss;
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index b00481cd5..45fa4cd11 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -6,7 +6,7 @@ use ra_syntax::{ast::self, TreeArc, SyntaxNode};
6 6
7use crate::{ 7use crate::{
8 Name, ScopesWithSourceMap, Ty, HirFileId, 8 Name, ScopesWithSourceMap, Ty, HirFileId,
9 HirDatabase, PersistentHirDatabase, 9 HirDatabase, DefDatabase,
10 type_ref::TypeRef, 10 type_ref::TypeRef,
11 nameres::{ModuleScope, Namespace, ImportId, CrateModuleId}, 11 nameres::{ModuleScope, Namespace, ImportId, CrateModuleId},
12 expr::{Body, BodySourceMap}, 12 expr::{Body, BodySourceMap},
@@ -38,24 +38,21 @@ impl Crate {
38 self.crate_id 38 self.crate_id
39 } 39 }
40 40
41 pub fn dependencies(&self, db: &impl PersistentHirDatabase) -> Vec<CrateDependency> { 41 pub fn dependencies(&self, db: &impl DefDatabase) -> Vec<CrateDependency> {
42 self.dependencies_impl(db) 42 self.dependencies_impl(db)
43 } 43 }
44 44
45 pub fn root_module(&self, db: &impl PersistentHirDatabase) -> Option<Module> { 45 pub fn root_module(&self, db: &impl DefDatabase) -> Option<Module> {
46 self.root_module_impl(db) 46 self.root_module_impl(db)
47 } 47 }
48 48
49 pub fn edition(&self, db: &impl PersistentHirDatabase) -> Edition { 49 pub fn edition(&self, db: &impl DefDatabase) -> Edition {
50 let crate_graph = db.crate_graph(); 50 let crate_graph = db.crate_graph();
51 crate_graph.edition(self.crate_id) 51 crate_graph.edition(self.crate_id)
52 } 52 }
53 53
54 // TODO: should this be in source_binder? 54 // FIXME: should this be in source_binder?
55 pub fn source_root_crates( 55 pub fn source_root_crates(db: &impl DefDatabase, source_root: SourceRootId) -> Vec<Crate> {
56 db: &impl PersistentHirDatabase,
57 source_root: SourceRootId,
58 ) -> Vec<Crate> {
59 let crate_ids = db.source_root_crates(source_root); 56 let crate_ids = db.source_root_crates(source_root);
60 crate_ids.iter().map(|&crate_id| Crate { crate_id }).collect() 57 crate_ids.iter().map(|&crate_id| Crate { crate_id }).collect()
61 } 58 }
@@ -101,7 +98,6 @@ pub enum ModuleSource {
101#[derive(Clone, Debug, Hash, PartialEq, Eq)] 98#[derive(Clone, Debug, Hash, PartialEq, Eq)]
102pub enum Problem { 99pub enum Problem {
103 UnresolvedModule { candidate: RelativePathBuf }, 100 UnresolvedModule { candidate: RelativePathBuf },
104 NotDirOwner { move_to: RelativePathBuf, candidate: RelativePathBuf },
105} 101}
106 102
107impl Module { 103impl Module {
@@ -111,7 +107,7 @@ impl Module {
111 } 107 }
112 108
113 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. 109 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
114 pub fn definition_source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, ModuleSource) { 110 pub fn definition_source(&self, db: &impl DefDatabase) -> (HirFileId, ModuleSource) {
115 self.definition_source_impl(db) 111 self.definition_source_impl(db)
116 } 112 }
117 113
@@ -134,14 +130,14 @@ impl Module {
134 } 130 }
135 131
136 /// Returns the crate this module is part of. 132 /// Returns the crate this module is part of.
137 pub fn krate(&self, _db: &impl PersistentHirDatabase) -> Option<Crate> { 133 pub fn krate(&self, _db: &impl DefDatabase) -> Option<Crate> {
138 Some(self.krate) 134 Some(self.krate)
139 } 135 }
140 136
141 /// Topmost parent of this module. Every module has a `crate_root`, but some 137 /// Topmost parent of this module. Every module has a `crate_root`, but some
142 /// might be missing `krate`. This can happen if a module's file is not included 138 /// might be missing `krate`. This can happen if a module's file is not included
143 /// in the module tree of any target in `Cargo.toml`. 139 /// in the module tree of any target in `Cargo.toml`.
144 pub fn crate_root(&self, db: &impl PersistentHirDatabase) -> Module { 140 pub fn crate_root(&self, db: &impl DefDatabase) -> Module {
145 self.crate_root_impl(db) 141 self.crate_root_impl(db)
146 } 142 }
147 143
@@ -151,12 +147,12 @@ impl Module {
151 } 147 }
152 148
153 /// Iterates over all child modules. 149 /// Iterates over all child modules.
154 pub fn children(&self, db: &impl PersistentHirDatabase) -> impl Iterator<Item = Module> { 150 pub fn children(&self, db: &impl DefDatabase) -> impl Iterator<Item = Module> {
155 self.children_impl(db) 151 self.children_impl(db)
156 } 152 }
157 153
158 /// Finds a parent module. 154 /// Finds a parent module.
159 pub fn parent(&self, db: &impl PersistentHirDatabase) -> Option<Module> { 155 pub fn parent(&self, db: &impl DefDatabase) -> Option<Module> {
160 self.parent_impl(db) 156 self.parent_impl(db)
161 } 157 }
162 158
@@ -229,7 +225,7 @@ impl StructField {
229 self.parent.variant_data(db).fields().unwrap()[self.id].name.clone() 225 self.parent.variant_data(db).fields().unwrap()[self.id].name.clone()
230 } 226 }
231 227
232 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, FieldSource) { 228 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, FieldSource) {
233 self.source_impl(db) 229 self.source_impl(db)
234 } 230 }
235 231
@@ -257,7 +253,7 @@ pub struct Struct {
257} 253}
258 254
259impl Struct { 255impl Struct {
260 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::StructDef>) { 256 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StructDef>) {
261 self.id.source(db) 257 self.id.source(db)
262 } 258 }
263 259
@@ -289,7 +285,7 @@ impl Struct {
289 .map(|(id, _)| StructField { parent: (*self).into(), id }) 285 .map(|(id, _)| StructField { parent: (*self).into(), id })
290 } 286 }
291 287
292 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { 288 pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> {
293 db.generic_params((*self).into()) 289 db.generic_params((*self).into())
294 } 290 }
295 291
@@ -301,7 +297,7 @@ impl Struct {
301 db.type_for_def((*self).into(), Namespace::Values) 297 db.type_for_def((*self).into(), Namespace::Values)
302 } 298 }
303 299
304 // TODO move to a more general type 300 // FIXME move to a more general type
305 /// Builds a resolver for type references inside this struct. 301 /// Builds a resolver for type references inside this struct.
306 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { 302 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
307 // take the outer scope... 303 // take the outer scope...
@@ -325,7 +321,7 @@ pub struct Enum {
325} 321}
326 322
327impl Enum { 323impl Enum {
328 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::EnumDef>) { 324 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::EnumDef>) {
329 self.id.source(db) 325 self.id.source(db)
330 } 326 }
331 327
@@ -337,7 +333,7 @@ impl Enum {
337 db.enum_data(*self).name.clone() 333 db.enum_data(*self).name.clone()
338 } 334 }
339 335
340 pub fn variants(&self, db: &impl PersistentHirDatabase) -> Vec<EnumVariant> { 336 pub fn variants(&self, db: &impl DefDatabase) -> Vec<EnumVariant> {
341 db.enum_data(*self) 337 db.enum_data(*self)
342 .variants 338 .variants
343 .iter() 339 .iter()
@@ -345,7 +341,7 @@ impl Enum {
345 .collect() 341 .collect()
346 } 342 }
347 343
348 pub fn variant(&self, db: &impl PersistentHirDatabase, name: &Name) -> Option<EnumVariant> { 344 pub fn variant(&self, db: &impl DefDatabase, name: &Name) -> Option<EnumVariant> {
349 db.enum_data(*self) 345 db.enum_data(*self)
350 .variants 346 .variants
351 .iter() 347 .iter()
@@ -353,7 +349,7 @@ impl Enum {
353 .map(|(id, _)| EnumVariant { parent: *self, id }) 349 .map(|(id, _)| EnumVariant { parent: *self, id })
354 } 350 }
355 351
356 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { 352 pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> {
357 db.generic_params((*self).into()) 353 db.generic_params((*self).into())
358 } 354 }
359 355
@@ -361,7 +357,7 @@ impl Enum {
361 db.type_for_def((*self).into(), Namespace::Types) 357 db.type_for_def((*self).into(), Namespace::Types)
362 } 358 }
363 359
364 // TODO: move to a more general type 360 // FIXME: move to a more general type
365 /// Builds a resolver for type references inside this struct. 361 /// Builds a resolver for type references inside this struct.
366 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { 362 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
367 // take the outer scope... 363 // take the outer scope...
@@ -386,20 +382,17 @@ pub struct EnumVariant {
386} 382}
387 383
388impl EnumVariant { 384impl EnumVariant {
389 pub fn source( 385 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::EnumVariant>) {
390 &self,
391 db: &impl PersistentHirDatabase,
392 ) -> (HirFileId, TreeArc<ast::EnumVariant>) {
393 self.source_impl(db) 386 self.source_impl(db)
394 } 387 }
395 pub fn module(&self, db: &impl HirDatabase) -> Module { 388 pub fn module(&self, db: &impl HirDatabase) -> Module {
396 self.parent.module(db) 389 self.parent.module(db)
397 } 390 }
398 pub fn parent_enum(&self, _db: &impl PersistentHirDatabase) -> Enum { 391 pub fn parent_enum(&self, _db: &impl DefDatabase) -> Enum {
399 self.parent 392 self.parent
400 } 393 }
401 394
402 pub fn name(&self, db: &impl PersistentHirDatabase) -> Option<Name> { 395 pub fn name(&self, db: &impl DefDatabase) -> Option<Name> {
403 db.enum_data(self.parent).variants[self.id].name.clone() 396 db.enum_data(self.parent).variants[self.id].name.clone()
404 } 397 }
405 398
@@ -465,11 +458,11 @@ impl FnSignature {
465} 458}
466 459
467impl Function { 460impl Function {
468 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::FnDef>) { 461 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::FnDef>) {
469 self.id.source(db) 462 self.id.source(db)
470 } 463 }
471 464
472 pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { 465 pub fn module(&self, db: &impl DefDatabase) -> Module {
473 self.id.module(db) 466 self.id.module(db)
474 } 467 }
475 468
@@ -503,17 +496,17 @@ impl Function {
503 db.infer(*self) 496 db.infer(*self)
504 } 497 }
505 498
506 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { 499 pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> {
507 db.generic_params((*self).into()) 500 db.generic_params((*self).into())
508 } 501 }
509 502
510 /// The containing impl block, if this is a method. 503 /// The containing impl block, if this is a method.
511 pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> { 504 pub fn impl_block(&self, db: &impl DefDatabase) -> Option<ImplBlock> {
512 let module_impls = db.impls_in_module(self.module(db)); 505 let module_impls = db.impls_in_module(self.module(db));
513 ImplBlock::containing(module_impls, (*self).into()) 506 ImplBlock::containing(module_impls, (*self).into())
514 } 507 }
515 508
516 // TODO: move to a more general type for 'body-having' items 509 // FIXME: move to a more general type for 'body-having' items
517 /// Builds a resolver for code inside this item. 510 /// Builds a resolver for code inside this item.
518 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { 511 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
519 // take the outer scope... 512 // take the outer scope...
@@ -540,11 +533,11 @@ pub struct Const {
540} 533}
541 534
542impl Const { 535impl Const {
543 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) { 536 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) {
544 self.id.source(db) 537 self.id.source(db)
545 } 538 }
546 539
547 pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { 540 pub fn module(&self, db: &impl DefDatabase) -> Module {
548 self.id.module(db) 541 self.id.module(db)
549 } 542 }
550 543
@@ -553,12 +546,12 @@ impl Const {
553 } 546 }
554 547
555 /// The containing impl block, if this is a method. 548 /// The containing impl block, if this is a method.
556 pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> { 549 pub fn impl_block(&self, db: &impl DefDatabase) -> Option<ImplBlock> {
557 let module_impls = db.impls_in_module(self.module(db)); 550 let module_impls = db.impls_in_module(self.module(db));
558 ImplBlock::containing(module_impls, (*self).into()) 551 ImplBlock::containing(module_impls, (*self).into())
559 } 552 }
560 553
561 // TODO: move to a more general type for 'body-having' items 554 // FIXME: move to a more general type for 'body-having' items
562 /// Builds a resolver for code inside this item. 555 /// Builds a resolver for code inside this item.
563 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { 556 pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
564 // take the outer scope... 557 // take the outer scope...
@@ -599,11 +592,11 @@ pub struct Static {
599} 592}
600 593
601impl Static { 594impl Static {
602 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) { 595 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) {
603 self.id.source(db) 596 self.id.source(db)
604 } 597 }
605 598
606 pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { 599 pub fn module(&self, db: &impl DefDatabase) -> Module {
607 self.id.module(db) 600 self.id.module(db)
608 } 601 }
609 602
@@ -630,15 +623,15 @@ pub struct Trait {
630} 623}
631 624
632impl Trait { 625impl Trait {
633 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) { 626 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) {
634 self.id.source(db) 627 self.id.source(db)
635 } 628 }
636 629
637 pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { 630 pub fn module(&self, db: &impl DefDatabase) -> Module {
638 self.id.module(db) 631 self.id.module(db)
639 } 632 }
640 633
641 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { 634 pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> {
642 db.generic_params((*self).into()) 635 db.generic_params((*self).into())
643 } 636 }
644} 637}
@@ -655,28 +648,25 @@ pub struct TypeAlias {
655} 648}
656 649
657impl TypeAlias { 650impl TypeAlias {
658 pub fn source( 651 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::TypeAliasDef>) {
659 &self,
660 db: &impl PersistentHirDatabase,
661 ) -> (HirFileId, TreeArc<ast::TypeAliasDef>) {
662 self.id.source(db) 652 self.id.source(db)
663 } 653 }
664 654
665 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { 655 pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> {
666 db.generic_params((*self).into()) 656 db.generic_params((*self).into())
667 } 657 }
668 658
669 pub fn module(&self, db: &impl PersistentHirDatabase) -> Module { 659 pub fn module(&self, db: &impl DefDatabase) -> Module {
670 self.id.module(db) 660 self.id.module(db)
671 } 661 }
672 662
673 /// The containing impl block, if this is a method. 663 /// The containing impl block, if this is a method.
674 pub fn impl_block(&self, db: &impl PersistentHirDatabase) -> Option<ImplBlock> { 664 pub fn impl_block(&self, db: &impl DefDatabase) -> Option<ImplBlock> {
675 let module_impls = db.impls_in_module(self.module(db)); 665 let module_impls = db.impls_in_module(self.module(db));
676 ImplBlock::containing(module_impls, (*self).into()) 666 ImplBlock::containing(module_impls, (*self).into())
677 } 667 }
678 668
679 pub fn type_ref(self, db: &impl PersistentHirDatabase) -> Arc<TypeRef> { 669 pub fn type_ref(self, db: &impl DefDatabase) -> Arc<TypeRef> {
680 db.type_alias_ref(self) 670 db.type_alias_ref(self)
681 } 671 }
682 672
diff --git a/crates/ra_hir/src/code_model_impl/function.rs b/crates/ra_hir/src/code_model_impl/function.rs
index c1654b069..334cb302b 100644
--- a/crates/ra_hir/src/code_model_impl/function.rs
+++ b/crates/ra_hir/src/code_model_impl/function.rs
@@ -5,14 +5,11 @@ use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
5use crate::{ 5use crate::{
6 Name, AsName, Function, FnSignature, 6 Name, AsName, Function, FnSignature,
7 type_ref::{TypeRef, Mutability}, 7 type_ref::{TypeRef, Mutability},
8 PersistentHirDatabase, 8 DefDatabase,
9}; 9};
10 10
11impl FnSignature { 11impl FnSignature {
12 pub(crate) fn fn_signature_query( 12 pub(crate) fn fn_signature_query(db: &impl DefDatabase, func: Function) -> Arc<FnSignature> {
13 db: &impl PersistentHirDatabase,
14 func: Function,
15 ) -> Arc<FnSignature> {
16 let (_, node) = func.source(db); 13 let (_, node) = func.source(db);
17 let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing); 14 let name = node.name().map(|n| n.as_name()).unwrap_or_else(Name::missing);
18 let mut params = Vec::new(); 15 let mut params = Vec::new();
diff --git a/crates/ra_hir/src/code_model_impl/konst.rs b/crates/ra_hir/src/code_model_impl/konst.rs
index 8b861a81f..db4e5ce5c 100644
--- a/crates/ra_hir/src/code_model_impl/konst.rs
+++ b/crates/ra_hir/src/code_model_impl/konst.rs
@@ -5,7 +5,7 @@ use ra_syntax::ast::{NameOwner, TypeAscriptionOwner};
5use crate::{ 5use crate::{
6 Name, AsName, Const, ConstSignature, Static, 6 Name, AsName, Const, ConstSignature, Static,
7 type_ref::{TypeRef}, 7 type_ref::{TypeRef},
8 PersistentHirDatabase, 8 DefDatabase,
9}; 9};
10 10
11fn const_signature_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstSignature> { 11fn const_signature_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstSignature> {
@@ -17,7 +17,7 @@ fn const_signature_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<Cons
17 17
18impl ConstSignature { 18impl ConstSignature {
19 pub(crate) fn const_signature_query( 19 pub(crate) fn const_signature_query(
20 db: &impl PersistentHirDatabase, 20 db: &impl DefDatabase,
21 konst: Const, 21 konst: Const,
22 ) -> Arc<ConstSignature> { 22 ) -> Arc<ConstSignature> {
23 let (_, node) = konst.source(db); 23 let (_, node) = konst.source(db);
@@ -25,7 +25,7 @@ impl ConstSignature {
25 } 25 }
26 26
27 pub(crate) fn static_signature_query( 27 pub(crate) fn static_signature_query(
28 db: &impl PersistentHirDatabase, 28 db: &impl DefDatabase,
29 konst: Static, 29 konst: Static,
30 ) -> Arc<ConstSignature> { 30 ) -> Arc<ConstSignature> {
31 let (_, node) = konst.source(db); 31 let (_, node) = konst.source(db);
diff --git a/crates/ra_hir/src/code_model_impl/krate.rs b/crates/ra_hir/src/code_model_impl/krate.rs
index cc87c6f14..914414fc3 100644
--- a/crates/ra_hir/src/code_model_impl/krate.rs
+++ b/crates/ra_hir/src/code_model_impl/krate.rs
@@ -1,12 +1,9 @@
1use crate::{ 1use crate::{
2 Crate, CrateDependency, AsName, Module, PersistentHirDatabase, 2 Crate, CrateDependency, AsName, Module, DefDatabase,
3}; 3};
4 4
5impl Crate { 5impl Crate {
6 pub(crate) fn dependencies_impl( 6 pub(crate) fn dependencies_impl(&self, db: &impl DefDatabase) -> Vec<CrateDependency> {
7 &self,
8 db: &impl PersistentHirDatabase,
9 ) -> Vec<CrateDependency> {
10 let crate_graph = db.crate_graph(); 7 let crate_graph = db.crate_graph();
11 crate_graph 8 crate_graph
12 .dependencies(self.crate_id) 9 .dependencies(self.crate_id)
@@ -17,7 +14,7 @@ impl Crate {
17 }) 14 })
18 .collect() 15 .collect()
19 } 16 }
20 pub(crate) fn root_module_impl(&self, db: &impl PersistentHirDatabase) -> Option<Module> { 17 pub(crate) fn root_module_impl(&self, db: &impl DefDatabase) -> Option<Module> {
21 let module_id = db.crate_def_map(*self).root(); 18 let module_id = db.crate_def_map(*self).root();
22 let module = Module { krate: *self, module_id }; 19 let module = Module { krate: *self, module_id };
23 Some(module) 20 Some(module)
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
index f7d15c55e..52a33e981 100644
--- a/crates/ra_hir/src/code_model_impl/module.rs
+++ b/crates/ra_hir/src/code_model_impl/module.rs
@@ -4,13 +4,13 @@ use ra_syntax::{ast, SyntaxNode, TreeArc, AstNode};
4use crate::{ 4use crate::{
5 Module, ModuleSource, Problem, Name, 5 Module, ModuleSource, Problem, Name,
6 nameres::{CrateModuleId, ImportId}, 6 nameres::{CrateModuleId, ImportId},
7 HirDatabase, PersistentHirDatabase, 7 HirDatabase, DefDatabase,
8 HirFileId, SourceItemId, 8 HirFileId, SourceItemId,
9}; 9};
10 10
11impl ModuleSource { 11impl ModuleSource {
12 pub(crate) fn new( 12 pub(crate) fn new(
13 db: &impl PersistentHirDatabase, 13 db: &impl DefDatabase,
14 file_id: Option<FileId>, 14 file_id: Option<FileId>,
15 decl_id: Option<SourceItemId>, 15 decl_id: Option<SourceItemId>,
16 ) -> ModuleSource { 16 ) -> ModuleSource {
@@ -49,7 +49,7 @@ impl Module {
49 49
50 pub(crate) fn definition_source_impl( 50 pub(crate) fn definition_source_impl(
51 &self, 51 &self,
52 db: &impl PersistentHirDatabase, 52 db: &impl DefDatabase,
53 ) -> (HirFileId, ModuleSource) { 53 ) -> (HirFileId, ModuleSource) {
54 let def_map = db.crate_def_map(self.krate); 54 let def_map = db.crate_def_map(self.krate);
55 let decl_id = def_map[self.module_id].declaration; 55 let decl_id = def_map[self.module_id].declaration;
@@ -80,7 +80,7 @@ impl Module {
80 source_map.get(&source, import) 80 source_map.get(&source, import)
81 } 81 }
82 82
83 pub(crate) fn crate_root_impl(&self, db: &impl PersistentHirDatabase) -> Module { 83 pub(crate) fn crate_root_impl(&self, db: &impl DefDatabase) -> Module {
84 let def_map = db.crate_def_map(self.krate); 84 let def_map = db.crate_def_map(self.krate);
85 self.with_module_id(def_map.root()) 85 self.with_module_id(def_map.root())
86 } 86 }
@@ -93,10 +93,7 @@ impl Module {
93 } 93 }
94 94
95 /// Iterates over all child modules. 95 /// Iterates over all child modules.
96 pub(crate) fn children_impl( 96 pub(crate) fn children_impl(&self, db: &impl DefDatabase) -> impl Iterator<Item = Module> {
97 &self,
98 db: &impl PersistentHirDatabase,
99 ) -> impl Iterator<Item = Module> {
100 let def_map = db.crate_def_map(self.krate); 97 let def_map = db.crate_def_map(self.krate);
101 let children = def_map[self.module_id] 98 let children = def_map[self.module_id]
102 .children 99 .children
@@ -106,7 +103,7 @@ impl Module {
106 children.into_iter() 103 children.into_iter()
107 } 104 }
108 105
109 pub(crate) fn parent_impl(&self, db: &impl PersistentHirDatabase) -> Option<Module> { 106 pub(crate) fn parent_impl(&self, db: &impl DefDatabase) -> Option<Module> {
110 let def_map = db.crate_def_map(self.krate); 107 let def_map = db.crate_def_map(self.krate);
111 let parent_id = def_map[self.module_id].parent?; 108 let parent_id = def_map[self.module_id].parent?;
112 Some(self.with_module_id(parent_id)) 109 Some(self.with_module_id(parent_id))
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index c7bad7e2b..d3908f8ac 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -16,8 +16,8 @@ use crate::{
16 type_ref::TypeRef, 16 type_ref::TypeRef,
17}; 17};
18 18
19#[salsa::query_group(PersistentHirDatabaseStorage)] 19#[salsa::query_group(DefDatabaseStorage)]
20pub trait PersistentHirDatabase: SourceDatabase + AsRef<HirInterner> { 20pub trait DefDatabase: SourceDatabase + AsRef<HirInterner> {
21 #[salsa::invoke(HirFileId::hir_parse)] 21 #[salsa::invoke(HirFileId::hir_parse)]
22 fn hir_parse(&self, file_id: HirFileId) -> TreeArc<SourceFile>; 22 fn hir_parse(&self, file_id: HirFileId) -> TreeArc<SourceFile>;
23 23
@@ -71,7 +71,7 @@ pub trait PersistentHirDatabase: SourceDatabase + AsRef<HirInterner> {
71} 71}
72 72
73#[salsa::query_group(HirDatabaseStorage)] 73#[salsa::query_group(HirDatabaseStorage)]
74pub trait HirDatabase: PersistentHirDatabase { 74pub trait HirDatabase: DefDatabase {
75 #[salsa::invoke(ExprScopes::expr_scopes_query)] 75 #[salsa::invoke(ExprScopes::expr_scopes_query)]
76 fn expr_scopes(&self, func: Function) -> Arc<ExprScopes>; 76 fn expr_scopes(&self, func: Function) -> Arc<ExprScopes>;
77 77
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index 0fadab560..703d99d9b 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -27,7 +27,7 @@ impl_arena_id!(ExprId);
27/// The body of an item (function, const etc.). 27/// The body of an item (function, const etc.).
28#[derive(Debug, Eq, PartialEq)] 28#[derive(Debug, Eq, PartialEq)]
29pub struct Body { 29pub struct Body {
30 // TODO: this should be more general, consts & statics also have bodies 30 // FIXME: this should be more general, consts & statics also have bodies
31 /// The Function of the item this body belongs to 31 /// The Function of the item this body belongs to
32 owner: Function, 32 owner: Function,
33 exprs: Arena<ExprId, Expr>, 33 exprs: Arena<ExprId, Expr>,
@@ -406,7 +406,7 @@ pub enum Pat {
406 Struct { 406 Struct {
407 path: Option<Path>, 407 path: Option<Path>,
408 args: Vec<FieldPat>, 408 args: Vec<FieldPat>,
409 // TODO: 'ellipsis' option 409 // FIXME: 'ellipsis' option
410 }, 410 },
411 Range { 411 Range {
412 start: ExprId, 412 start: ExprId,
@@ -547,7 +547,7 @@ impl ExprCollector {
547 if condition.pat().is_none() { 547 if condition.pat().is_none() {
548 self.collect_expr_opt(condition.expr()) 548 self.collect_expr_opt(condition.expr())
549 } else { 549 } else {
550 // TODO handle while let 550 // FIXME handle while let
551 return self.alloc_expr(Expr::Missing, syntax_ptr); 551 return self.alloc_expr(Expr::Missing, syntax_ptr);
552 } 552 }
553 } else { 553 } else {
@@ -610,7 +610,7 @@ impl ExprCollector {
610 self.alloc_expr(path, syntax_ptr) 610 self.alloc_expr(path, syntax_ptr)
611 } 611 }
612 ast::ExprKind::ContinueExpr(_e) => { 612 ast::ExprKind::ContinueExpr(_e) => {
613 // TODO: labels 613 // FIXME: labels
614 self.alloc_expr(Expr::Continue, syntax_ptr) 614 self.alloc_expr(Expr::Continue, syntax_ptr)
615 } 615 }
616 ast::ExprKind::BreakExpr(e) => { 616 ast::ExprKind::BreakExpr(e) => {
@@ -751,7 +751,7 @@ impl ExprCollector {
751 self.alloc_expr(Expr::Literal(lit), syntax_ptr) 751 self.alloc_expr(Expr::Literal(lit), syntax_ptr)
752 } 752 }
753 753
754 // TODO implement HIR for these: 754 // FIXME implement HIR for these:
755 ast::ExprKind::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), 755 ast::ExprKind::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
756 ast::ExprKind::IndexExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), 756 ast::ExprKind::IndexExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
757 ast::ExprKind::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr), 757 ast::ExprKind::RangeExpr(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
@@ -844,7 +844,7 @@ impl ExprCollector {
844 Pat::Struct { path, args: fields } 844 Pat::Struct { path, args: fields }
845 } 845 }
846 846
847 // TODO: implement 847 // FIXME: implement
848 ast::PatKind::LiteralPat(_) => Pat::Missing, 848 ast::PatKind::LiteralPat(_) => Pat::Missing,
849 ast::PatKind::SlicePat(_) | ast::PatKind::RangePat(_) => Pat::Missing, 849 ast::PatKind::SlicePat(_) | ast::PatKind::RangePat(_) => Pat::Missing,
850 }; 850 };
@@ -910,7 +910,7 @@ pub(crate) fn body_with_source_map_query(
910) -> (Arc<Body>, Arc<BodySourceMap>) { 910) -> (Arc<Body>, Arc<BodySourceMap>) {
911 let mut collector = ExprCollector::new(func); 911 let mut collector = ExprCollector::new(func);
912 912
913 // TODO: consts, etc. 913 // FIXME: consts, etc.
914 collector.collect_fn_body(&func.source(db).1); 914 collector.collect_fn_body(&func.source(db).1);
915 915
916 let (body, source_map) = collector.finish(); 916 let (body, source_map) = collector.finish();
diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs
index 81fbc509e..ed005c9f7 100644
--- a/crates/ra_hir/src/expr/scope.rs
+++ b/crates/ra_hir/src/expr/scope.rs
@@ -39,7 +39,7 @@ pub struct ScopeData {
39} 39}
40 40
41impl ExprScopes { 41impl ExprScopes {
42 // TODO: This should take something more general than Function 42 // FIXME: This should take something more general than Function
43 pub(crate) fn expr_scopes_query(db: &impl HirDatabase, function: Function) -> Arc<ExprScopes> { 43 pub(crate) fn expr_scopes_query(db: &impl HirDatabase, function: Function) -> Arc<ExprScopes> {
44 let body = db.body_hir(function); 44 let body = db.body_hir(function);
45 let res = ExprScopes::new(body); 45 let res = ExprScopes::new(body);
@@ -148,7 +148,7 @@ impl ScopesWithSourceMap {
148 148
149 // XXX: during completion, cursor might be outside of any particular 149 // XXX: during completion, cursor might be outside of any particular
150 // expression. Try to figure out the correct scope... 150 // expression. Try to figure out the correct scope...
151 // TODO: move this to source binder? 151 // FIXME: move this to source binder?
152 fn adjust(&self, ptr: SyntaxNodePtr, original_scope: ScopeId, offset: TextUnit) -> ScopeId { 152 fn adjust(&self, ptr: SyntaxNodePtr, original_scope: ScopeId, offset: TextUnit) -> ScopeId {
153 let r = ptr.range(); 153 let r = ptr.range();
154 let child_scopes = self 154 let child_scopes = self
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index 0f759a235..84fe94289 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -8,14 +8,14 @@ use std::sync::Arc;
8use ra_syntax::ast::{self, NameOwner, TypeParamsOwner}; 8use ra_syntax::ast::{self, NameOwner, TypeParamsOwner};
9 9
10use crate::{ 10use crate::{
11 db::PersistentHirDatabase, 11 db::DefDatabase,
12 Name, AsName, Function, Struct, Enum, Trait, TypeAlias, ImplBlock 12 Name, AsName, Function, Struct, Enum, Trait, TypeAlias, ImplBlock
13}; 13};
14 14
15/// Data about a generic parameter (to a function, struct, impl, ...). 15/// Data about a generic parameter (to a function, struct, impl, ...).
16#[derive(Clone, PartialEq, Eq, Debug)] 16#[derive(Clone, PartialEq, Eq, Debug)]
17pub struct GenericParam { 17pub struct GenericParam {
18 // TODO: give generic params proper IDs 18 // FIXME: give generic params proper IDs
19 pub(crate) idx: u32, 19 pub(crate) idx: u32,
20 pub(crate) name: Name, 20 pub(crate) name: Name,
21} 21}
@@ -40,7 +40,7 @@ impl_froms!(GenericDef: Function, Struct, Enum, Trait, TypeAlias, ImplBlock);
40 40
41impl GenericParams { 41impl GenericParams {
42 pub(crate) fn generic_params_query( 42 pub(crate) fn generic_params_query(
43 db: &impl PersistentHirDatabase, 43 db: &impl DefDatabase,
44 def: GenericDef, 44 def: GenericDef,
45 ) -> Arc<GenericParams> { 45 ) -> Arc<GenericParams> {
46 let mut generics = GenericParams::default(); 46 let mut generics = GenericParams::default();
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 3d0a881c2..18401f865 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -10,7 +10,7 @@ use ra_arena::{Arena, RawId, ArenaId, impl_arena_id};
10 10
11use crate::{ 11use crate::{
12 Module, 12 Module,
13 PersistentHirDatabase, 13 DefDatabase,
14}; 14};
15 15
16#[derive(Debug, Default)] 16#[derive(Debug, Default)]
@@ -63,7 +63,7 @@ pub struct HirFileId(HirFileIdRepr);
63impl HirFileId { 63impl HirFileId {
64 /// For macro-expansion files, returns the file original source file the 64 /// For macro-expansion files, returns the file original source file the
65 /// expansion originated from. 65 /// expansion originated from.
66 pub fn original_file(self, db: &impl PersistentHirDatabase) -> FileId { 66 pub fn original_file(self, db: &impl DefDatabase) -> FileId {
67 match self.0 { 67 match self.0 {
68 HirFileIdRepr::File(file_id) => file_id, 68 HirFileIdRepr::File(file_id) => file_id,
69 HirFileIdRepr::Macro(macro_call_id) => { 69 HirFileIdRepr::Macro(macro_call_id) => {
@@ -83,10 +83,7 @@ impl HirFileId {
83 } 83 }
84 } 84 }
85 85
86 pub(crate) fn hir_parse( 86 pub(crate) fn hir_parse(db: &impl DefDatabase, file_id: HirFileId) -> TreeArc<SourceFile> {
87 db: &impl PersistentHirDatabase,
88 file_id: HirFileId,
89 ) -> TreeArc<SourceFile> {
90 match file_id.0 { 87 match file_id.0 {
91 HirFileIdRepr::File(file_id) => db.parse(file_id), 88 HirFileIdRepr::File(file_id) => db.parse(file_id),
92 HirFileIdRepr::Macro(macro_call_id) => { 89 HirFileIdRepr::Macro(macro_call_id) => {
@@ -97,10 +94,7 @@ impl HirFileId {
97 } 94 }
98} 95}
99 96
100fn parse_macro( 97fn parse_macro(db: &impl DefDatabase, macro_call_id: MacroCallId) -> Option<TreeArc<SourceFile>> {
101 db: &impl PersistentHirDatabase,
102 macro_call_id: MacroCallId,
103) -> Option<TreeArc<SourceFile>> {
104 let loc = macro_call_id.loc(db); 98 let loc = macro_call_id.loc(db);
105 let syntax = db.file_item(loc.source_item_id); 99 let syntax = db.file_item(loc.source_item_id);
106 let macro_call = ast::MacroCall::cast(&syntax).unwrap(); 100 let macro_call = ast::MacroCall::cast(&syntax).unwrap();
@@ -190,7 +184,7 @@ pub(crate) struct LocationCtx<DB> {
190 file_id: HirFileId, 184 file_id: HirFileId,
191} 185}
192 186
193impl<'a, DB: PersistentHirDatabase> LocationCtx<&'a DB> { 187impl<'a, DB: DefDatabase> LocationCtx<&'a DB> {
194 pub(crate) fn new(db: &'a DB, module: Module, file_id: HirFileId) -> LocationCtx<&'a DB> { 188 pub(crate) fn new(db: &'a DB, module: Module, file_id: HirFileId) -> LocationCtx<&'a DB> {
195 LocationCtx { db, module, file_id } 189 LocationCtx { db, module, file_id }
196 } 190 }
@@ -205,13 +199,13 @@ impl<'a, DB: PersistentHirDatabase> LocationCtx<&'a DB> {
205 199
206pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone { 200pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone {
207 fn interner(interner: &HirInterner) -> &LocationInterner<ItemLoc<N>, Self>; 201 fn interner(interner: &HirInterner) -> &LocationInterner<ItemLoc<N>, Self>;
208 fn from_ast(ctx: LocationCtx<&impl PersistentHirDatabase>, ast: &N) -> Self { 202 fn from_ast(ctx: LocationCtx<&impl DefDatabase>, ast: &N) -> Self {
209 let items = ctx.db.file_items(ctx.file_id); 203 let items = ctx.db.file_items(ctx.file_id);
210 let item_id = items.id_of(ctx.file_id, ast.syntax()); 204 let item_id = items.id_of(ctx.file_id, ast.syntax());
211 Self::from_source_item_id_unchecked(ctx, item_id) 205 Self::from_source_item_id_unchecked(ctx, item_id)
212 } 206 }
213 fn from_source_item_id_unchecked( 207 fn from_source_item_id_unchecked(
214 ctx: LocationCtx<&impl PersistentHirDatabase>, 208 ctx: LocationCtx<&impl DefDatabase>,
215 item_id: SourceFileItemId, 209 item_id: SourceFileItemId,
216 ) -> Self { 210 ) -> Self {
217 let raw = SourceItemId { file_id: ctx.file_id, item_id }; 211 let raw = SourceItemId { file_id: ctx.file_id, item_id };
@@ -219,7 +213,7 @@ pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone {
219 213
220 Self::interner(ctx.db.as_ref()).loc2id(&loc) 214 Self::interner(ctx.db.as_ref()).loc2id(&loc)
221 } 215 }
222 fn source(self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<N>) { 216 fn source(self, db: &impl DefDatabase) -> (HirFileId, TreeArc<N>) {
223 let int = Self::interner(db.as_ref()); 217 let int = Self::interner(db.as_ref());
224 let loc = int.id2loc(self); 218 let loc = int.id2loc(self);
225 let syntax = db.file_item(loc.raw); 219 let syntax = db.file_item(loc.raw);
@@ -227,7 +221,7 @@ pub(crate) trait AstItemDef<N: AstNode>: ArenaId + Clone {
227 N::cast(&syntax).unwrap_or_else(|| panic!("invalid ItemLoc: {:?}", loc.raw)).to_owned(); 221 N::cast(&syntax).unwrap_or_else(|| panic!("invalid ItemLoc: {:?}", loc.raw)).to_owned();
228 (loc.raw.file_id, ast) 222 (loc.raw.file_id, ast)
229 } 223 }
230 fn module(self, db: &impl PersistentHirDatabase) -> Module { 224 fn module(self, db: &impl DefDatabase) -> Module {
231 let int = Self::interner(db.as_ref()); 225 let int = Self::interner(db.as_ref());
232 let loc = int.id2loc(self); 226 let loc = int.id2loc(self);
233 loc.module 227 loc.module
@@ -324,7 +318,7 @@ pub struct SourceFileItems {
324 318
325impl SourceFileItems { 319impl SourceFileItems {
326 pub(crate) fn file_items_query( 320 pub(crate) fn file_items_query(
327 db: &impl PersistentHirDatabase, 321 db: &impl DefDatabase,
328 file_id: HirFileId, 322 file_id: HirFileId,
329 ) -> Arc<SourceFileItems> { 323 ) -> Arc<SourceFileItems> {
330 let source_file = db.hir_parse(file_id); 324 let source_file = db.hir_parse(file_id);
@@ -332,7 +326,7 @@ impl SourceFileItems {
332 } 326 }
333 327
334 pub(crate) fn file_item_query( 328 pub(crate) fn file_item_query(
335 db: &impl PersistentHirDatabase, 329 db: &impl DefDatabase,
336 source_item_id: SourceItemId, 330 source_item_id: SourceItemId,
337 ) -> TreeArc<SyntaxNode> { 331 ) -> TreeArc<SyntaxNode> {
338 let source_file = db.hir_parse(source_item_id.file_id); 332 let source_file = db.hir_parse(source_item_id.file_id);
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index 8807a4b56..40d368cd9 100644
--- a/crates/ra_hir/src/impl_block.rs
+++ b/crates/ra_hir/src/impl_block.rs
@@ -9,7 +9,7 @@ use ra_syntax::{
9 9
10use crate::{ 10use crate::{
11 Const, TypeAlias, Function, HirFileId, 11 Const, TypeAlias, Function, HirFileId,
12 HirDatabase, PersistentHirDatabase, 12 HirDatabase, DefDatabase,
13 ModuleDef, Trait, Resolution, 13 ModuleDef, Trait, Resolution,
14 type_ref::TypeRef, 14 type_ref::TypeRef,
15 ids::LocationCtx, 15 ids::LocationCtx,
@@ -59,7 +59,7 @@ impl ImplBlock {
59 } 59 }
60 60
61 /// Returns the syntax of the impl block 61 /// Returns the syntax of the impl block
62 pub fn source(&self, db: &impl PersistentHirDatabase) -> (HirFileId, TreeArc<ast::ImplBlock>) { 62 pub fn source(&self, db: &impl DefDatabase) -> (HirFileId, TreeArc<ast::ImplBlock>) {
63 let source_map = db.impls_in_module_source_map(self.module); 63 let source_map = db.impls_in_module_source_map(self.module);
64 let (file_id, source) = self.module.definition_source(db); 64 let (file_id, source) = self.module.definition_source(db);
65 (file_id, source_map.get(&source, self.impl_id)) 65 (file_id, source_map.get(&source, self.impl_id))
@@ -73,11 +73,11 @@ impl ImplBlock {
73 self.module 73 self.module
74 } 74 }
75 75
76 pub fn target_trait_ref(&self, db: &impl PersistentHirDatabase) -> Option<TypeRef> { 76 pub fn target_trait_ref(&self, db: &impl DefDatabase) -> Option<TypeRef> {
77 db.impls_in_module(self.module).impls[self.impl_id].target_trait().cloned() 77 db.impls_in_module(self.module).impls[self.impl_id].target_trait().cloned()
78 } 78 }
79 79
80 pub fn target_type(&self, db: &impl PersistentHirDatabase) -> TypeRef { 80 pub fn target_type(&self, db: &impl DefDatabase) -> TypeRef {
81 db.impls_in_module(self.module).impls[self.impl_id].target_type().clone() 81 db.impls_in_module(self.module).impls[self.impl_id].target_type().clone()
82 } 82 }
83 83
@@ -97,11 +97,11 @@ impl ImplBlock {
97 None 97 None
98 } 98 }
99 99
100 pub fn items(&self, db: &impl PersistentHirDatabase) -> Vec<ImplItem> { 100 pub fn items(&self, db: &impl DefDatabase) -> Vec<ImplItem> {
101 db.impls_in_module(self.module).impls[self.impl_id].items().to_vec() 101 db.impls_in_module(self.module).impls[self.impl_id].items().to_vec()
102 } 102 }
103 103
104 pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { 104 pub fn generic_params(&self, db: &impl DefDatabase) -> Arc<GenericParams> {
105 db.generic_params((*self).into()) 105 db.generic_params((*self).into())
106 } 106 }
107 107
@@ -124,7 +124,7 @@ pub struct ImplData {
124 124
125impl ImplData { 125impl ImplData {
126 pub(crate) fn from_ast( 126 pub(crate) fn from_ast(
127 db: &impl PersistentHirDatabase, 127 db: &impl DefDatabase,
128 file_id: HirFileId, 128 file_id: HirFileId,
129 module: Module, 129 module: Module,
130 node: &ast::ImplBlock, 130 node: &ast::ImplBlock,
@@ -161,7 +161,7 @@ impl ImplData {
161} 161}
162 162
163#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 163#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
164//TODO: rename to ImplDef? 164//FIXME: rename to ImplDef?
165pub enum ImplItem { 165pub enum ImplItem {
166 Method(Function), 166 Method(Function),
167 Const(Const), 167 Const(Const),
@@ -193,11 +193,7 @@ pub struct ModuleImplBlocks {
193} 193}
194 194
195impl ModuleImplBlocks { 195impl ModuleImplBlocks {
196 fn collect( 196 fn collect(db: &impl DefDatabase, module: Module, source_map: &mut ImplSourceMap) -> Self {
197 db: &impl PersistentHirDatabase,
198 module: Module,
199 source_map: &mut ImplSourceMap,
200 ) -> Self {
201 let mut m = ModuleImplBlocks { 197 let mut m = ModuleImplBlocks {
202 module, 198 module,
203 impls: Arena::default(), 199 impls: Arena::default(),
@@ -228,7 +224,7 @@ impl ModuleImplBlocks {
228} 224}
229 225
230pub(crate) fn impls_in_module_with_source_map_query( 226pub(crate) fn impls_in_module_with_source_map_query(
231 db: &impl PersistentHirDatabase, 227 db: &impl DefDatabase,
232 module: Module, 228 module: Module,
233) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>) { 229) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>) {
234 let mut source_map = ImplSourceMap::default(); 230 let mut source_map = ImplSourceMap::default();
@@ -238,15 +234,12 @@ pub(crate) fn impls_in_module_with_source_map_query(
238 (Arc::new(result), Arc::new(source_map)) 234 (Arc::new(result), Arc::new(source_map))
239} 235}
240 236
241pub(crate) fn impls_in_module( 237pub(crate) fn impls_in_module(db: &impl DefDatabase, module: Module) -> Arc<ModuleImplBlocks> {
242 db: &impl PersistentHirDatabase,
243 module: Module,
244) -> Arc<ModuleImplBlocks> {
245 db.impls_in_module_with_source_map(module).0 238 db.impls_in_module_with_source_map(module).0
246} 239}
247 240
248pub(crate) fn impls_in_module_source_map_query( 241pub(crate) fn impls_in_module_source_map_query(
249 db: &impl PersistentHirDatabase, 242 db: &impl DefDatabase,
250 module: Module, 243 module: Module,
251) -> Arc<ImplSourceMap> { 244) -> Arc<ImplSourceMap> {
252 db.impls_in_module_with_source_map(module).1 245 db.impls_in_module_with_source_map(module).1
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 5926b5758..a89c916f8 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -43,7 +43,7 @@ mod code_model_impl;
43mod marks; 43mod marks;
44 44
45use crate::{ 45use crate::{
46 db::{HirDatabase, PersistentHirDatabase}, 46 db::{HirDatabase, DefDatabase},
47 name::{AsName, KnownName}, 47 name::{AsName, KnownName},
48 ids::{SourceItemId, SourceFileItems}, 48 ids::{SourceItemId, SourceFileItems},
49}; 49};
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs
index f1cad77c5..10d4c1b8c 100644
--- a/crates/ra_hir/src/mock.rs
+++ b/crates/ra_hir/src/mock.rs
@@ -13,11 +13,7 @@ use crate::{db, HirInterner};
13 13
14pub const WORKSPACE: SourceRootId = SourceRootId(0); 14pub const WORKSPACE: SourceRootId = SourceRootId(0);
15 15
16#[salsa::database( 16#[salsa::database(ra_db::SourceDatabaseStorage, db::HirDatabaseStorage, db::DefDatabaseStorage)]
17 ra_db::SourceDatabaseStorage,
18 db::HirDatabaseStorage,
19 db::PersistentHirDatabaseStorage
20)]
21#[derive(Debug)] 17#[derive(Debug)]
22pub struct MockDatabase { 18pub struct MockDatabase {
23 events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>, 19 events: Mutex<Option<Vec<salsa::Event<MockDatabase>>>>,
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index edd2f25f7..d361cf9e6 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -62,7 +62,7 @@ use test_utils::tested_by;
62 62
63use crate::{ 63use crate::{
64 ModuleDef, Name, Crate, Module, Problem, 64 ModuleDef, Name, Crate, Module, Problem,
65 PersistentHirDatabase, Path, PathKind, HirFileId, 65 DefDatabase, Path, PathKind, HirFileId,
66 ids::{SourceItemId, SourceFileItemId, MacroCallId}, 66 ids::{SourceItemId, SourceFileItemId, MacroCallId},
67}; 67};
68 68
@@ -196,10 +196,7 @@ enum ReachedFixedPoint {
196} 196}
197 197
198impl CrateDefMap { 198impl CrateDefMap {
199 pub(crate) fn crate_def_map_query( 199 pub(crate) fn crate_def_map_query(db: &impl DefDatabase, krate: Crate) -> Arc<CrateDefMap> {
200 db: &impl PersistentHirDatabase,
201 krate: Crate,
202 ) -> Arc<CrateDefMap> {
203 let start = std::time::Instant::now(); 200 let start = std::time::Instant::now();
204 let def_map = { 201 let def_map = {
205 let edition = krate.edition(db); 202 let edition = krate.edition(db);
@@ -268,7 +265,7 @@ impl CrateDefMap {
268 265
269 pub(crate) fn resolve_path( 266 pub(crate) fn resolve_path(
270 &self, 267 &self,
271 db: &impl PersistentHirDatabase, 268 db: &impl DefDatabase,
272 original_module: CrateModuleId, 269 original_module: CrateModuleId,
273 path: &Path, 270 path: &Path,
274 ) -> (PerNs<ModuleDef>, Option<usize>) { 271 ) -> (PerNs<ModuleDef>, Option<usize>) {
@@ -280,7 +277,7 @@ impl CrateDefMap {
280 // the result. 277 // the result.
281 fn resolve_path_fp( 278 fn resolve_path_fp(
282 &self, 279 &self,
283 db: &impl PersistentHirDatabase, 280 db: &impl DefDatabase,
284 mode: ResolveMode, 281 mode: ResolveMode,
285 original_module: CrateModuleId, 282 original_module: CrateModuleId,
286 path: &Path, 283 path: &Path,
@@ -296,7 +293,7 @@ impl CrateDefMap {
296 // plain import or absolute path in 2015: crate-relative with 293 // plain import or absolute path in 2015: crate-relative with
297 // fallback to extern prelude (with the simplification in 294 // fallback to extern prelude (with the simplification in
298 // rust-lang/rust#57745) 295 // rust-lang/rust#57745)
299 // TODO there must be a nicer way to write this condition 296 // FIXME there must be a nicer way to write this condition
300 PathKind::Plain | PathKind::Abs 297 PathKind::Plain | PathKind::Abs
301 if self.edition == Edition::Edition2015 298 if self.edition == Edition::Edition2015
302 && (path.kind == PathKind::Abs || mode == ResolveMode::Import) => 299 && (path.kind == PathKind::Abs || mode == ResolveMode::Import) =>
@@ -422,7 +419,7 @@ impl CrateDefMap {
422 419
423 pub(crate) fn resolve_name_in_module( 420 pub(crate) fn resolve_name_in_module(
424 &self, 421 &self,
425 db: &impl PersistentHirDatabase, 422 db: &impl DefDatabase,
426 module: CrateModuleId, 423 module: CrateModuleId,
427 name: &Name, 424 name: &Name,
428 ) -> PerNs<ModuleDef> { 425 ) -> PerNs<ModuleDef> {
@@ -442,7 +439,7 @@ impl CrateDefMap {
442 self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it)) 439 self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it))
443 } 440 }
444 441
445 fn resolve_in_prelude(&self, db: &impl PersistentHirDatabase, name: &Name) -> PerNs<ModuleDef> { 442 fn resolve_in_prelude(&self, db: &impl DefDatabase, name: &Name) -> PerNs<ModuleDef> {
446 if let Some(prelude) = self.prelude { 443 if let Some(prelude) = self.prelude {
447 let resolution = if prelude.krate == self.krate { 444 let resolution = if prelude.krate == self.krate {
448 self[prelude.module_id].scope.items.get(name).cloned() 445 self[prelude.module_id].scope.items.get(name).cloned()
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index 3ea8d592c..c5b73cfbe 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -6,7 +6,7 @@ use ra_db::FileId;
6 6
7use crate::{ 7use crate::{
8 Function, Module, Struct, Enum, Const, Static, Trait, TypeAlias, 8 Function, Module, Struct, Enum, Const, Static, Trait, TypeAlias,
9 PersistentHirDatabase, HirFileId, Name, Path, Problem, Crate, 9 DefDatabase, HirFileId, Name, Path, Problem, Crate,
10 KnownName, 10 KnownName,
11 nameres::{Resolution, PerNs, ModuleDef, ReachedFixedPoint, ResolveMode, raw}, 11 nameres::{Resolution, PerNs, ModuleDef, ReachedFixedPoint, ResolveMode, raw},
12 ids::{AstItemDef, LocationCtx, MacroCallLoc, SourceItemId, MacroCallId}, 12 ids::{AstItemDef, LocationCtx, MacroCallLoc, SourceItemId, MacroCallId},
@@ -14,10 +14,7 @@ use crate::{
14 14
15use super::{CrateDefMap, CrateModuleId, ModuleData, CrateMacroId}; 15use super::{CrateDefMap, CrateModuleId, ModuleData, CrateMacroId};
16 16
17pub(super) fn collect_defs( 17pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
18 db: &impl PersistentHirDatabase,
19 mut def_map: CrateDefMap,
20) -> CrateDefMap {
21 // populate external prelude 18 // populate external prelude
22 for dep in def_map.krate.dependencies(db) { 19 for dep in def_map.krate.dependencies(db) {
23 log::debug!("crate dep {:?} -> {:?}", dep.name, dep.krate); 20 log::debug!("crate dep {:?} -> {:?}", dep.name, dep.krate);
@@ -57,7 +54,7 @@ struct DefCollector<DB> {
57 54
58impl<'a, DB> DefCollector<&'a DB> 55impl<'a, DB> DefCollector<&'a DB>
59where 56where
60 DB: PersistentHirDatabase, 57 DB: DefDatabase,
61{ 58{
62 fn collect(&mut self) { 59 fn collect(&mut self) {
63 let crate_graph = self.db.crate_graph(); 60 let crate_graph = self.db.crate_graph();
@@ -370,7 +367,7 @@ struct ModCollector<'a, D> {
370 367
371impl<DB> ModCollector<'_, &'_ mut DefCollector<&'_ DB>> 368impl<DB> ModCollector<'_, &'_ mut DefCollector<&'_ DB>>
372where 369where
373 DB: PersistentHirDatabase, 370 DB: DefDatabase,
374{ 371{
375 fn collect(&mut self, items: &[raw::RawItem]) { 372 fn collect(&mut self, items: &[raw::RawItem]) {
376 for item in items { 373 for item in items {
@@ -523,7 +520,7 @@ fn is_macro_rules(path: &Path) -> bool {
523} 520}
524 521
525fn resolve_submodule( 522fn resolve_submodule(
526 db: &impl PersistentHirDatabase, 523 db: &impl DefDatabase,
527 file_id: HirFileId, 524 file_id: HirFileId,
528 name: &Name, 525 name: &Name,
529 is_root: bool, 526 is_root: bool,
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir/src/nameres/raw.rs
index 3226bbf0d..f8ba398ec 100644
--- a/crates/ra_hir/src/nameres/raw.rs
+++ b/crates/ra_hir/src/nameres/raw.rs
@@ -12,7 +12,7 @@ use ra_syntax::{
12}; 12};
13 13
14use crate::{ 14use crate::{
15 PersistentHirDatabase, Name, AsName, Path, HirFileId, ModuleSource, 15 DefDatabase, Name, AsName, Path, HirFileId, ModuleSource,
16 ids::{SourceFileItemId, SourceFileItems}, 16 ids::{SourceFileItemId, SourceFileItems},
17}; 17};
18 18
@@ -47,15 +47,12 @@ impl ImportSourceMap {
47} 47}
48 48
49impl RawItems { 49impl RawItems {
50 pub(crate) fn raw_items_query( 50 pub(crate) fn raw_items_query(db: &impl DefDatabase, file_id: FileId) -> Arc<RawItems> {
51 db: &impl PersistentHirDatabase,
52 file_id: FileId,
53 ) -> Arc<RawItems> {
54 db.raw_items_with_source_map(file_id).0 51 db.raw_items_with_source_map(file_id).0
55 } 52 }
56 53
57 pub(crate) fn raw_items_with_source_map_query( 54 pub(crate) fn raw_items_with_source_map_query(
58 db: &impl PersistentHirDatabase, 55 db: &impl DefDatabase,
59 file_id: FileId, 56 file_id: FileId,
60 ) -> (Arc<RawItems>, Arc<ImportSourceMap>) { 57 ) -> (Arc<RawItems>, Arc<ImportSourceMap>) {
61 let mut collector = RawItemsCollector { 58 let mut collector = RawItemsCollector {
diff --git a/crates/ra_hir/src/path.rs b/crates/ra_hir/src/path.rs
index 6ca373e34..6cc8104f4 100644
--- a/crates/ra_hir/src/path.rs
+++ b/crates/ra_hir/src/path.rs
@@ -96,7 +96,7 @@ impl Path {
96 if let Some(q) = path.qualifier() { 96 if let Some(q) = path.qualifier() {
97 return Some(q); 97 return Some(q);
98 } 98 }
99 // TODO: this bottom up traversal is not too precise. 99 // FIXME: this bottom up traversal is not too precise.
100 // Should we handle do a top-down analysis, recording results? 100 // Should we handle do a top-down analysis, recording results?
101 let use_tree_list = path.syntax().ancestors().find_map(ast::UseTreeList::cast)?; 101 let use_tree_list = path.syntax().ancestors().find_map(ast::UseTreeList::cast)?;
102 let use_tree = use_tree_list.parent_use_tree(); 102 let use_tree = use_tree_list.parent_use_tree();
@@ -166,7 +166,7 @@ fn expand_use_tree<'a>(
166 // or `use something::{path::{inner::{innerer}}}` (prefix is `something::path`, path is `inner`) 166 // or `use something::{path::{inner::{innerer}}}` (prefix is `something::path`, path is `inner`)
167 Some(path) => match convert_path(prefix, path) { 167 Some(path) => match convert_path(prefix, path) {
168 Some(it) => Some(it), 168 Some(it) => Some(it),
169 None => return, // TODO: report errors somewhere 169 None => return, // FIXME: report errors somewhere
170 }, 170 },
171 }; 171 };
172 for child_tree in use_tree_list.use_trees() { 172 for child_tree in use_tree_list.use_trees() {
@@ -194,7 +194,7 @@ fn expand_use_tree<'a>(
194 cb(path, Some(segment), alias) 194 cb(path, Some(segment), alias)
195 }; 195 };
196 } 196 }
197 // TODO: report errors somewhere 197 // FIXME: report errors somewhere
198 // We get here if we do 198 // We get here if we do
199 } 199 }
200 } 200 }
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs
index 59af4ec60..f28154517 100644
--- a/crates/ra_hir/src/resolve.rs
+++ b/crates/ra_hir/src/resolve.rs
@@ -19,7 +19,7 @@ pub struct Resolver {
19 scopes: Vec<Scope>, 19 scopes: Vec<Scope>,
20} 20}
21 21
22// TODO how to store these best 22// FIXME how to store these best
23#[derive(Debug, Clone)] 23#[derive(Debug, Clone)]
24pub(crate) struct ModuleItemMap { 24pub(crate) struct ModuleItemMap {
25 crate_def_map: Arc<CrateDefMap>, 25 crate_def_map: Arc<CrateDefMap>,
@@ -260,7 +260,7 @@ impl Scope {
260 fn collect_names(&self, db: &impl HirDatabase, f: &mut dyn FnMut(Name, PerNs<Resolution>)) { 260 fn collect_names(&self, db: &impl HirDatabase, f: &mut dyn FnMut(Name, PerNs<Resolution>)) {
261 match self { 261 match self {
262 Scope::ModuleScope(m) => { 262 Scope::ModuleScope(m) => {
263 // TODO: should we provide `self` here? 263 // FIXME: should we provide `self` here?
264 // f( 264 // f(
265 // Name::self_param(), 265 // Name::self_param(),
266 // PerNs::types(Resolution::Def { 266 // PerNs::types(Resolution::Def {
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 902110913..3645b73b4 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -164,7 +164,7 @@ pub fn resolver_for_position(db: &impl HirDatabase, position: FilePosition) -> R
164 let scope = scopes.scope_for_offset(position.offset); 164 let scope = scopes.scope_for_offset(position.offset);
165 Some(expr::resolver_for_scope(func.body(db), db, scope)) 165 Some(expr::resolver_for_scope(func.body(db), db, scope))
166 } else { 166 } else {
167 // TODO const/static/array length 167 // FIXME const/static/array length
168 None 168 None
169 } 169 }
170 } else { 170 } else {
@@ -184,7 +184,7 @@ pub fn resolver_for_node(db: &impl HirDatabase, file_id: FileId, node: &SyntaxNo
184 let scope = scopes.scope_for(&node); 184 let scope = scopes.scope_for(&node);
185 Some(expr::resolver_for_scope(func.body(db), db, scope)) 185 Some(expr::resolver_for_scope(func.body(db), db, scope))
186 } else { 186 } else {
187 // TODO const/static/array length 187 // FIXME const/static/array length
188 None 188 None
189 } 189 }
190 } else { 190 } else {
@@ -212,7 +212,7 @@ fn try_get_resolver_for_node(
212 } else if let Some(f) = ast::FnDef::cast(node) { 212 } else if let Some(f) = ast::FnDef::cast(node) {
213 function_from_source(db, file_id, f).map(|f| f.resolver(db)) 213 function_from_source(db, file_id, f).map(|f| f.resolver(db))
214 } else { 214 } else {
215 // TODO add missing cases 215 // FIXME add missing cases
216 None 216 None
217 } 217 }
218} 218}
diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs
index d95879e46..ab5f008ef 100644
--- a/crates/ra_hir/src/ty/autoderef.rs
+++ b/crates/ra_hir/src/ty/autoderef.rs
@@ -15,7 +15,7 @@ impl Ty {
15 } 15 }
16 16
17 fn autoderef_step(&self, _db: &impl HirDatabase) -> Option<Ty> { 17 fn autoderef_step(&self, _db: &impl HirDatabase) -> Option<Ty> {
18 // TODO Deref::deref 18 // FIXME Deref::deref
19 self.builtin_deref() 19 self.builtin_deref()
20 } 20 }
21} 21}
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index 7cf465266..cff7e7481 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -207,7 +207,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
207 fn make_ty(&mut self, type_ref: &TypeRef) -> Ty { 207 fn make_ty(&mut self, type_ref: &TypeRef) -> Ty {
208 let ty = Ty::from_hir( 208 let ty = Ty::from_hir(
209 self.db, 209 self.db,
210 // TODO use right resolver for block 210 // FIXME use right resolver for block
211 &self.resolver, 211 &self.resolver,
212 type_ref, 212 type_ref,
213 ); 213 );
@@ -407,18 +407,18 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
407 407
408 let substs = 408 let substs =
409 Ty::substs_from_path_segment(self.db, &self.resolver, segment, typable); 409 Ty::substs_from_path_segment(self.db, &self.resolver, segment, typable);
410 self.db.type_for_def(typable, Namespace::Types).apply_substs(substs) 410 self.db.type_for_def(typable, Namespace::Types).subst(&substs)
411 } 411 }
412 Resolution::LocalBinding(_) => { 412 Resolution::LocalBinding(_) => {
413 // can't have a local binding in an associated item path 413 // can't have a local binding in an associated item path
414 return None; 414 return None;
415 } 415 }
416 Resolution::GenericParam(..) => { 416 Resolution::GenericParam(..) => {
417 // TODO associated item of generic param 417 // FIXME associated item of generic param
418 return None; 418 return None;
419 } 419 }
420 Resolution::SelfType(_) => { 420 Resolution::SelfType(_) => {
421 // TODO associated item of self type 421 // FIXME associated item of self type
422 return None; 422 return None;
423 } 423 }
424 }; 424 };
@@ -446,7 +446,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
446 } 446 }
447 } 447 }
448 448
449 // TODO: Resolve associated types 449 // FIXME: Resolve associated types
450 crate::ImplItem::TypeAlias(_) => None, 450 crate::ImplItem::TypeAlias(_) => None,
451 }; 451 };
452 match matching_def { 452 match matching_def {
@@ -466,7 +466,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
466 let typable: Option<TypableDef> = def.into(); 466 let typable: Option<TypableDef> = def.into();
467 let typable = typable?; 467 let typable = typable?;
468 let substs = Ty::substs_from_path(self.db, &self.resolver, path, typable); 468 let substs = Ty::substs_from_path(self.db, &self.resolver, path, typable);
469 let ty = self.db.type_for_def(typable, Namespace::Values).apply_substs(substs); 469 let ty = self.db.type_for_def(typable, Namespace::Values).subst(&substs);
470 let ty = self.insert_type_vars(ty); 470 let ty = self.insert_type_vars(ty);
471 Some(ty) 471 Some(ty)
472 } 472 }
@@ -504,7 +504,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
504 return (Ty::Unknown, None); 504 return (Ty::Unknown, None);
505 } 505 }
506 Some(Resolution::SelfType(..)) => { 506 Some(Resolution::SelfType(..)) => {
507 // TODO this is allowed in an impl for a struct, handle this 507 // FIXME this is allowed in an impl for a struct, handle this
508 return (Ty::Unknown, None); 508 return (Ty::Unknown, None);
509 } 509 }
510 None => return (Ty::Unknown, None), 510 None => return (Ty::Unknown, None),
@@ -513,7 +513,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
513 None => return (Ty::Unknown, None), 513 None => return (Ty::Unknown, None),
514 Some(it) => it, 514 Some(it) => it,
515 }; 515 };
516 // TODO remove the duplication between here and `Ty::from_path`? 516 // FIXME remove the duplication between here and `Ty::from_path`?
517 let substs = Ty::substs_from_path(self.db, resolver, path, def); 517 let substs = Ty::substs_from_path(self.db, resolver, path, def);
518 match def { 518 match def {
519 TypableDef::Struct(s) => { 519 TypableDef::Struct(s) => {
@@ -590,7 +590,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
590 | Pat::Struct { .. } 590 | Pat::Struct { .. }
591 | Pat::Range { .. } 591 | Pat::Range { .. }
592 | Pat::Slice { .. } => true, 592 | Pat::Slice { .. } => true,
593 // TODO: Path/Lit might actually evaluate to ref, but inference is unimplemented. 593 // FIXME: Path/Lit might actually evaluate to ref, but inference is unimplemented.
594 Pat::Path(..) | Pat::Lit(..) => true, 594 Pat::Path(..) | Pat::Lit(..) => true,
595 Pat::Wild | Pat::Bind { .. } | Pat::Ref { .. } | Pat::Missing => false, 595 Pat::Wild | Pat::Bind { .. } | Pat::Ref { .. } | Pat::Missing => false,
596 }; 596 };
@@ -635,7 +635,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
635 let expectation = match expected.as_reference() { 635 let expectation = match expected.as_reference() {
636 Some((inner_ty, exp_mut)) => { 636 Some((inner_ty, exp_mut)) => {
637 if *mutability != exp_mut { 637 if *mutability != exp_mut {
638 // TODO: emit type error? 638 // FIXME: emit type error?
639 } 639 }
640 inner_ty 640 inner_ty
641 } 641 }
@@ -651,7 +651,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
651 self.infer_struct_pat(p.as_ref(), fields, expected, default_bm) 651 self.infer_struct_pat(p.as_ref(), fields, expected, default_bm)
652 } 652 }
653 Pat::Path(path) => { 653 Pat::Path(path) => {
654 // TODO use correct resolver for the surrounding expression 654 // FIXME use correct resolver for the surrounding expression
655 let resolver = self.resolver.clone(); 655 let resolver = self.resolver.clone();
656 self.infer_path_expr(&resolver, &path, pat.into()).unwrap_or(Ty::Unknown) 656 self.infer_path_expr(&resolver, &path, pat.into()).unwrap_or(Ty::Unknown)
657 } 657 }
@@ -741,7 +741,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
741 Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected), 741 Expr::Block { statements, tail } => self.infer_block(statements, *tail, expected),
742 Expr::Loop { body } => { 742 Expr::Loop { body } => {
743 self.infer_expr(*body, &Expectation::has_type(Ty::unit())); 743 self.infer_expr(*body, &Expectation::has_type(Ty::unit()));
744 // TODO handle break with value 744 // FIXME handle break with value
745 Ty::simple(TypeCtor::Never) 745 Ty::simple(TypeCtor::Never)
746 } 746 }
747 Expr::While { condition, body } => { 747 Expr::While { condition, body } => {
@@ -769,7 +769,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
769 self.infer_pat(*arg_pat, &expected, BindingMode::default()); 769 self.infer_pat(*arg_pat, &expected, BindingMode::default());
770 } 770 }
771 771
772 // TODO: infer lambda type etc. 772 // FIXME: infer lambda type etc.
773 let _body_ty = self.infer_expr(*body, &Expectation::none()); 773 let _body_ty = self.infer_expr(*body, &Expectation::none());
774 Ty::Unknown 774 Ty::Unknown
775 } 775 }
@@ -795,7 +795,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
795 }, 795 },
796 _ => { 796 _ => {
797 // not callable 797 // not callable
798 // TODO report an error? 798 // FIXME report an error?
799 (Vec::new(), Ty::Unknown) 799 (Vec::new(), Ty::Unknown)
800 } 800 }
801 }; 801 };
@@ -894,14 +894,14 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
894 expected.ty 894 expected.ty
895 } 895 }
896 Expr::Path(p) => { 896 Expr::Path(p) => {
897 // TODO this could be more efficient... 897 // FIXME this could be more efficient...
898 let resolver = expr::resolver_for_expr(self.body.clone(), self.db, tgt_expr); 898 let resolver = expr::resolver_for_expr(self.body.clone(), self.db, tgt_expr);
899 self.infer_path_expr(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown) 899 self.infer_path_expr(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown)
900 } 900 }
901 Expr::Continue => Ty::simple(TypeCtor::Never), 901 Expr::Continue => Ty::simple(TypeCtor::Never),
902 Expr::Break { expr } => { 902 Expr::Break { expr } => {
903 if let Some(expr) = expr { 903 if let Some(expr) = expr {
904 // TODO handle break with value 904 // FIXME handle break with value
905 self.infer_expr(*expr, &Expectation::none()); 905 self.infer_expr(*expr, &Expectation::none());
906 } 906 }
907 Ty::simple(TypeCtor::Never) 907 Ty::simple(TypeCtor::Never)
@@ -957,21 +957,21 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
957 Expr::Cast { expr, type_ref } => { 957 Expr::Cast { expr, type_ref } => {
958 let _inner_ty = self.infer_expr(*expr, &Expectation::none()); 958 let _inner_ty = self.infer_expr(*expr, &Expectation::none());
959 let cast_ty = self.make_ty(type_ref); 959 let cast_ty = self.make_ty(type_ref);
960 // TODO check the cast... 960 // FIXME check the cast...
961 cast_ty 961 cast_ty
962 } 962 }
963 Expr::Ref { expr, mutability } => { 963 Expr::Ref { expr, mutability } => {
964 let expectation = 964 let expectation =
965 if let Some((exp_inner, exp_mutability)) = &expected.ty.as_reference() { 965 if let Some((exp_inner, exp_mutability)) = &expected.ty.as_reference() {
966 if *exp_mutability == Mutability::Mut && *mutability == Mutability::Shared { 966 if *exp_mutability == Mutability::Mut && *mutability == Mutability::Shared {
967 // TODO: throw type error - expected mut reference but found shared ref, 967 // FIXME: throw type error - expected mut reference but found shared ref,
968 // which cannot be coerced 968 // which cannot be coerced
969 } 969 }
970 Expectation::has_type(Ty::clone(exp_inner)) 970 Expectation::has_type(Ty::clone(exp_inner))
971 } else { 971 } else {
972 Expectation::none() 972 Expectation::none()
973 }; 973 };
974 // TODO reference coercions etc. 974 // FIXME reference coercions etc.
975 let inner_ty = self.infer_expr(*expr, &expectation); 975 let inner_ty = self.infer_expr(*expr, &expectation);
976 Ty::apply_one(TypeCtor::Ref(*mutability), inner_ty) 976 Ty::apply_one(TypeCtor::Ref(*mutability), inner_ty)
977 } 977 }
@@ -982,7 +982,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
982 if let Some(derefed_ty) = inner_ty.builtin_deref() { 982 if let Some(derefed_ty) = inner_ty.builtin_deref() {
983 derefed_ty 983 derefed_ty
984 } else { 984 } else {
985 // TODO Deref::deref 985 // FIXME Deref::deref
986 Ty::Unknown 986 Ty::Unknown
987 } 987 }
988 } 988 }
@@ -1002,7 +1002,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1002 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => { 1002 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => {
1003 inner_ty 1003 inner_ty
1004 } 1004 }
1005 // TODO: resolve ops::Neg trait 1005 // FIXME: resolve ops::Neg trait
1006 _ => Ty::Unknown, 1006 _ => Ty::Unknown,
1007 } 1007 }
1008 } 1008 }
@@ -1013,7 +1013,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1013 _ => Ty::Unknown, 1013 _ => Ty::Unknown,
1014 }, 1014 },
1015 Ty::Infer(InferTy::IntVar(..)) => inner_ty, 1015 Ty::Infer(InferTy::IntVar(..)) => inner_ty,
1016 // TODO: resolve ops::Not trait for inner_ty 1016 // FIXME: resolve ops::Not trait for inner_ty
1017 _ => Ty::Unknown, 1017 _ => Ty::Unknown,
1018 } 1018 }
1019 } 1019 }
@@ -1028,12 +1028,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
1028 _ => Expectation::none(), 1028 _ => Expectation::none(),
1029 }; 1029 };
1030 let lhs_ty = self.infer_expr(*lhs, &lhs_expectation); 1030 let lhs_ty = self.infer_expr(*lhs, &lhs_expectation);
1031 // TODO: find implementation of trait corresponding to operation 1031 // FIXME: find implementation of trait corresponding to operation
1032 // symbol and resolve associated `Output` type 1032 // symbol and resolve associated `Output` type
1033 let rhs_expectation = op::binary_op_rhs_expectation(*op, lhs_ty); 1033 let rhs_expectation = op::binary_op_rhs_expectation(*op, lhs_ty);
1034 let rhs_ty = self.infer_expr(*rhs, &Expectation::has_type(rhs_expectation)); 1034 let rhs_ty = self.infer_expr(*rhs, &Expectation::has_type(rhs_expectation));
1035 1035
1036 // TODO: similar as above, return ty is often associated trait type 1036 // FIXME: similar as above, return ty is often associated trait type
1037 op::binary_op_return_ty(*op, rhs_ty) 1037 op::binary_op_return_ty(*op, rhs_ty)
1038 } 1038 }
1039 _ => Ty::Unknown, 1039 _ => Ty::Unknown,
@@ -1227,7 +1227,7 @@ impl InferTy {
1227#[derive(Clone, PartialEq, Eq, Debug)] 1227#[derive(Clone, PartialEq, Eq, Debug)]
1228struct Expectation { 1228struct Expectation {
1229 ty: Ty, 1229 ty: Ty,
1230 // TODO: In some cases, we need to be aware whether the expectation is that 1230 // FIXME: In some cases, we need to be aware whether the expectation is that
1231 // the type match exactly what we passed, or whether it just needs to be 1231 // the type match exactly what we passed, or whether it just needs to be
1232 // coercible to the expected type. See Expectation::rvalue_hint in rustc. 1232 // coercible to the expected type. See Expectation::rvalue_hint in rustc.
1233} 1233}
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index 7f9af307b..003a89f0d 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -60,7 +60,7 @@ impl Ty {
60 60
61 pub(crate) fn from_hir_path(db: &impl HirDatabase, resolver: &Resolver, path: &Path) -> Self { 61 pub(crate) fn from_hir_path(db: &impl HirDatabase, resolver: &Resolver, path: &Path) -> Self {
62 if let Some(name) = path.as_ident() { 62 if let Some(name) = path.as_ident() {
63 // TODO handle primitive type names in resolver as well? 63 // FIXME handle primitive type names in resolver as well?
64 if let Some(int_ty) = primitive::IntTy::from_type_name(name) { 64 if let Some(int_ty) = primitive::IntTy::from_type_name(name) {
65 return Ty::simple(TypeCtor::Int(primitive::UncertainIntTy::Known(int_ty))); 65 return Ty::simple(TypeCtor::Int(primitive::UncertainIntTy::Known(int_ty)));
66 } else if let Some(float_ty) = primitive::FloatTy::from_type_name(name) { 66 } else if let Some(float_ty) = primitive::FloatTy::from_type_name(name) {
@@ -87,7 +87,7 @@ impl Ty {
87 Some(Resolution::GenericParam(idx)) => { 87 Some(Resolution::GenericParam(idx)) => {
88 return Ty::Param { 88 return Ty::Param {
89 idx, 89 idx,
90 // TODO: maybe return name in resolution? 90 // FIXME: maybe return name in resolution?
91 name: path 91 name: path
92 .as_ident() 92 .as_ident()
93 .expect("generic param should be single-segment path") 93 .expect("generic param should be single-segment path")
@@ -139,7 +139,7 @@ impl Ty {
139 } 139 }
140 } 140 }
141 // add placeholders for args that were not provided 141 // add placeholders for args that were not provided
142 // TODO: handle defaults 142 // FIXME: handle defaults
143 let supplied_params = substs.len(); 143 let supplied_params = substs.len();
144 for _ in supplied_params..def_generics.count_params_including_parent() { 144 for _ in supplied_params..def_generics.count_params_including_parent() {
145 substs.push(Ty::Unknown); 145 substs.push(Ty::Unknown);
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index ed75bfaee..b1684acf9 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -120,7 +120,7 @@ fn def_crate(db: &impl HirDatabase, ty: &Ty) -> Option<Crate> {
120} 120}
121 121
122impl Ty { 122impl Ty {
123 // TODO: cache this as a query? 123 // FIXME: cache this as a query?
124 // - if so, what signature? (TyFingerprint, Name)? 124 // - if so, what signature? (TyFingerprint, Name)?
125 // - or maybe cache all names and def_ids of methods per fingerprint? 125 // - or maybe cache all names and def_ids of methods per fingerprint?
126 /// Look up the method with the given name, returning the actual autoderefed 126 /// Look up the method with the given name, returning the actual autoderefed
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 0f2172ddf..5d8ad4aa7 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -1792,6 +1792,29 @@ fn test<R>(query_response: Canonical<QueryResponse<R>>) {
1792} 1792}
1793 1793
1794#[test] 1794#[test]
1795fn bug_1030() {
1796 assert_snapshot_matches!(infer(r#"
1797struct HashSet<T, H>;
1798struct FxHasher;
1799type FxHashSet<T> = HashSet<T, FxHasher>;
1800
1801impl<T, H> HashSet<T, H> {
1802 fn default() -> HashSet<T, H> {}
1803}
1804
1805pub fn main_loop() {
1806 FxHashSet::default();
1807}
1808"#),
1809 @r###"
1810[144; 146) '{}': ()
1811[169; 198) '{ ...t(); }': ()
1812[175; 193) 'FxHash...efault': fn default<{unknown}, {unknown}>() -> HashSet<T, H>
1813[175; 195) 'FxHash...ault()': HashSet<{unknown}, {unknown}>"###
1814 );
1815}
1816
1817#[test]
1795fn cross_crate_associated_method_call() { 1818fn cross_crate_associated_method_call() {
1796 let (mut db, pos) = MockDatabase::with_position( 1819 let (mut db, pos) = MockDatabase::with_position(
1797 r#" 1820 r#"
diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir/src/type_alias.rs
index d02762d20..e35adcb2f 100644
--- a/crates/ra_hir/src/type_alias.rs
+++ b/crates/ra_hir/src/type_alias.rs
@@ -2,12 +2,9 @@
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use crate::{TypeAlias, db::PersistentHirDatabase, type_ref::TypeRef}; 5use crate::{TypeAlias, db::DefDatabase, type_ref::TypeRef};
6 6
7pub(crate) fn type_alias_ref_query( 7pub(crate) fn type_alias_ref_query(db: &impl DefDatabase, typ: TypeAlias) -> Arc<TypeRef> {
8 db: &impl PersistentHirDatabase,
9 typ: TypeAlias,
10) -> Arc<TypeRef> {
11 let (_, node) = typ.source(db); 8 let (_, node) = typ.source(db);
12 Arc::new(TypeRef::from_ast_opt(node.type_ref())) 9 Arc::new(TypeRef::from_ast_opt(node.type_ref()))
13} 10}