aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/adt.rs4
-rw-r--r--crates/ra_hir/src/code_model.rs49
-rw-r--r--crates/ra_hir/src/db.rs22
-rw-r--r--crates/ra_hir/src/expr.rs6
-rw-r--r--crates/ra_hir/src/expr/lower.rs10
-rw-r--r--crates/ra_hir/src/expr/validation.rs2
-rw-r--r--crates/ra_hir/src/from_source.rs44
-rw-r--r--crates/ra_hir/src/generics.rs20
-rw-r--r--crates/ra_hir/src/impl_block.rs3
-rw-r--r--crates/ra_hir/src/lib.rs23
-rw-r--r--crates/ra_hir/src/marks.rs1
-rw-r--r--crates/ra_hir/src/mock.rs1
-rw-r--r--crates/ra_hir/src/nameres.rs11
-rw-r--r--crates/ra_hir/src/nameres/collector.rs7
-rw-r--r--crates/ra_hir/src/nameres/tests/mod_resolution.rs2
-rw-r--r--crates/ra_hir/src/resolve.rs22
-rw-r--r--crates/ra_hir/src/source_binder.rs6
-rw-r--r--crates/ra_hir/src/traits.rs4
-rw-r--r--crates/ra_hir/src/ty.rs4
-rw-r--r--crates/ra_hir/src/ty/autoderef.rs3
-rw-r--r--crates/ra_hir/src/ty/infer.rs8
-rw-r--r--crates/ra_hir/src/ty/infer/coerce.rs3
-rw-r--r--crates/ra_hir/src/ty/infer/expr.rs7
-rw-r--r--crates/ra_hir/src/ty/infer/path.rs6
-rw-r--r--crates/ra_hir/src/ty/lower.rs7
-rw-r--r--crates/ra_hir/src/ty/method_resolution.rs3
-rw-r--r--crates/ra_hir/src/ty/traits/chalk.rs3
-rw-r--r--crates/ra_hir/src/type_alias.rs6
-rw-r--r--crates/ra_hir_def/Cargo.toml7
-rw-r--r--crates/ra_hir_def/src/attr.rs (renamed from crates/ra_hir/src/attr.rs)15
-rw-r--r--crates/ra_hir_def/src/db.rs18
-rw-r--r--crates/ra_hir_def/src/either.rs (renamed from crates/ra_hir/src/either.rs)0
-rw-r--r--crates/ra_hir_def/src/lib.rs95
-rw-r--r--crates/ra_hir_def/src/name.rs (renamed from crates/ra_hir/src/name.rs)78
-rw-r--r--crates/ra_hir_def/src/nameres.rs3
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs (renamed from crates/ra_hir/src/nameres/raw.rs)66
-rw-r--r--crates/ra_hir_def/src/path.rs (renamed from crates/ra_hir/src/path.rs)27
-rw-r--r--crates/ra_hir_def/src/type_ref.rs (renamed from crates/ra_hir/src/type_ref.rs)8
-rw-r--r--crates/ra_hir_expand/src/lib.rs8
-rw-r--r--crates/ra_ide_api/src/db.rs1
40 files changed, 343 insertions, 270 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index 3e9cd3c63..d16b3a1cc 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -3,13 +3,13 @@
3 3
4use std::sync::Arc; 4use std::sync::Arc;
5 5
6use hir_def::{name::AsName, type_ref::TypeRef};
6use ra_arena::{impl_arena_id, Arena, RawId}; 7use ra_arena::{impl_arena_id, Arena, RawId};
7use ra_syntax::ast::{self, NameOwner, StructKind, TypeAscriptionOwner}; 8use ra_syntax::ast::{self, NameOwner, StructKind, TypeAscriptionOwner};
8 9
9use crate::{ 10use crate::{
10 db::{AstDatabase, DefDatabase, HirDatabase}, 11 db::{AstDatabase, DefDatabase, HirDatabase},
11 type_ref::TypeRef, 12 Enum, EnumVariant, FieldSource, HasSource, Module, Name, Source, Struct, StructField,
12 AsName, Enum, EnumVariant, FieldSource, HasSource, Module, Name, Source, Struct, StructField,
13}; 13};
14 14
15impl Struct { 15impl Struct {
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 1a790b2f3..d865c972e 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -5,8 +5,15 @@ pub(crate) mod docs;
5 5
6use std::sync::Arc; 6use std::sync::Arc;
7 7
8use hir_def::{CrateModuleId, ModuleId}; 8use hir_def::{
9use ra_db::{CrateId, Edition, FileId}; 9 name::{
10 self, AsName, BOOL, CHAR, F32, F64, I128, I16, I32, I64, I8, ISIZE, SELF_TYPE, STR, U128,
11 U16, U32, U64, U8, USIZE,
12 },
13 type_ref::{Mutability, TypeRef},
14 CrateModuleId, ModuleId,
15};
16use ra_db::{CrateId, Edition};
10use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner}; 17use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
11 18
12use crate::{ 19use crate::{
@@ -20,10 +27,6 @@ use crate::{
20 TypeAliasId, 27 TypeAliasId,
21 }, 28 },
22 impl_block::ImplBlock, 29 impl_block::ImplBlock,
23 name::{
24 BOOL, CHAR, F32, F64, I128, I16, I32, I64, I8, ISIZE, SELF_TYPE, STR, U128, U16, U32, U64,
25 U8, USIZE,
26 },
27 nameres::{ImportId, ModuleScope, Namespace}, 30 nameres::{ImportId, ModuleScope, Namespace},
28 resolve::{Resolver, Scope, TypeNs}, 31 resolve::{Resolver, Scope, TypeNs},
29 traits::TraitData, 32 traits::TraitData,
@@ -31,9 +34,7 @@ use crate::{
31 primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness}, 34 primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness},
32 InferenceResult, TraitRef, 35 InferenceResult, TraitRef,
33 }, 36 },
34 type_ref::Mutability, 37 Either, HasSource, Name, Ty,
35 type_ref::TypeRef,
36 AsName, AstId, Either, HasSource, Name, Ty,
37}; 38};
38 39
39/// hir::Crate describes a single crate. It's the main interface with which 40/// hir::Crate describes a single crate. It's the main interface with which
@@ -147,31 +148,7 @@ impl_froms!(
147 BuiltinType 148 BuiltinType
148); 149);
149 150
150pub enum ModuleSource { 151pub use hir_def::ModuleSource;
151 SourceFile(ast::SourceFile),
152 Module(ast::Module),
153}
154
155impl ModuleSource {
156 pub(crate) fn new(
157 db: &(impl DefDatabase + AstDatabase),
158 file_id: Option<FileId>,
159 decl_id: Option<AstId<ast::Module>>,
160 ) -> ModuleSource {
161 match (file_id, decl_id) {
162 (Some(file_id), _) => {
163 let source_file = db.parse(file_id).tree();
164 ModuleSource::SourceFile(source_file)
165 }
166 (None, Some(item_id)) => {
167 let module = item_id.to_node(db);
168 assert!(module.item_list().is_some(), "expected inline module");
169 ModuleSource::Module(module)
170 }
171 (None, None) => panic!(),
172 }
173 }
174}
175 152
176impl Module { 153impl Module {
177 pub(crate) fn new(krate: Crate, crate_module_id: CrateModuleId) -> Module { 154 pub(crate) fn new(krate: Crate, crate_module_id: CrateModuleId) -> Module {
@@ -922,9 +899,7 @@ impl Trait {
922 .where_predicates 899 .where_predicates
923 .iter() 900 .iter()
924 .filter_map(|pred| match &pred.type_ref { 901 .filter_map(|pred| match &pred.type_ref {
925 TypeRef::Path(p) if p.as_ident() == Some(&crate::name::SELF_TYPE) => { 902 TypeRef::Path(p) if p.as_ident() == Some(&name::SELF_TYPE) => pred.bound.as_path(),
926 pred.bound.as_path()
927 }
928 _ => None, 903 _ => None,
929 }) 904 })
930 .filter_map(|path| match resolver.resolve_path_in_type_ns_fully(db, path) { 905 .filter_map(|path| match resolver.resolve_path_in_type_ns_fully(db, path) {
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index 8f6cb2da7..ebfd970eb 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -12,18 +12,21 @@ use crate::{
12 ids, 12 ids,
13 impl_block::{ImplBlock, ImplSourceMap, ModuleImplBlocks}, 13 impl_block::{ImplBlock, ImplSourceMap, ModuleImplBlocks},
14 lang_item::{LangItemTarget, LangItems}, 14 lang_item::{LangItemTarget, LangItems},
15 nameres::{CrateDefMap, ImportSourceMap, Namespace, RawItems}, 15 nameres::{CrateDefMap, Namespace},
16 traits::TraitData, 16 traits::TraitData,
17 ty::{ 17 ty::{
18 method_resolution::CrateImplBlocks, traits::Impl, CallableDef, FnSig, GenericPredicate, 18 method_resolution::CrateImplBlocks, traits::Impl, CallableDef, FnSig, GenericPredicate,
19 InferenceResult, Substs, Ty, TypableDef, TypeCtor, 19 InferenceResult, Substs, Ty, TypableDef, TypeCtor,
20 }, 20 },
21 type_alias::TypeAliasData, 21 type_alias::TypeAliasData,
22 Const, ConstData, Crate, DefWithBody, Enum, ExprScopes, FnData, Function, HirFileId, Module, 22 Const, ConstData, Crate, DefWithBody, Enum, ExprScopes, FnData, Function, Module, Static,
23 Static, Struct, StructField, Trait, TypeAlias, 23 Struct, StructField, Trait, TypeAlias,
24}; 24};
25 25
26pub use hir_def::db::{InternDatabase, InternDatabaseStorage}; 26pub use hir_def::db::{
27 DefDatabase2, DefDatabase2Storage, InternDatabase, InternDatabaseStorage, RawItemsQuery,
28 RawItemsWithSourceMapQuery,
29};
27pub use hir_expand::db::{ 30pub use hir_expand::db::{
28 AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, 31 AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
29 ParseMacroQuery, 32 ParseMacroQuery,
@@ -32,7 +35,7 @@ pub use hir_expand::db::{
32// This database uses `AstDatabase` internally, 35// This database uses `AstDatabase` internally,
33#[salsa::query_group(DefDatabaseStorage)] 36#[salsa::query_group(DefDatabaseStorage)]
34#[salsa::requires(AstDatabase)] 37#[salsa::requires(AstDatabase)]
35pub trait DefDatabase: InternDatabase + HirDebugDatabase + AstDatabase { 38pub trait DefDatabase: HirDebugDatabase + DefDatabase2 {
36 #[salsa::invoke(crate::adt::StructData::struct_data_query)] 39 #[salsa::invoke(crate::adt::StructData::struct_data_query)]
37 fn struct_data(&self, s: Struct) -> Arc<StructData>; 40 fn struct_data(&self, s: Struct) -> Arc<StructData>;
38 41
@@ -45,15 +48,6 @@ pub trait DefDatabase: InternDatabase + HirDebugDatabase + AstDatabase {
45 #[salsa::invoke(crate::traits::TraitItemsIndex::trait_items_index)] 48 #[salsa::invoke(crate::traits::TraitItemsIndex::trait_items_index)]
46 fn trait_items_index(&self, module: Module) -> crate::traits::TraitItemsIndex; 49 fn trait_items_index(&self, module: Module) -> crate::traits::TraitItemsIndex;
47 50
48 #[salsa::invoke(RawItems::raw_items_with_source_map_query)]
49 fn raw_items_with_source_map(
50 &self,
51 file_id: HirFileId,
52 ) -> (Arc<RawItems>, Arc<ImportSourceMap>);
53
54 #[salsa::invoke(RawItems::raw_items_query)]
55 fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>;
56
57 #[salsa::invoke(CrateDefMap::crate_def_map_query)] 51 #[salsa::invoke(CrateDefMap::crate_def_map_query)]
58 fn crate_def_map(&self, krate: Crate) -> Arc<CrateDefMap>; 52 fn crate_def_map(&self, krate: Crate) -> Arc<CrateDefMap>;
59 53
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index d238741ba..6e23197a4 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -6,15 +6,17 @@ pub(crate) mod validation;
6 6
7use std::{ops::Index, sync::Arc}; 7use std::{ops::Index, sync::Arc};
8 8
9use hir_def::{
10 path::GenericArgs,
11 type_ref::{Mutability, TypeRef},
12};
9use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; 13use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
10use ra_syntax::{ast, AstPtr}; 14use ra_syntax::{ast, AstPtr};
11use rustc_hash::FxHashMap; 15use rustc_hash::FxHashMap;
12 16
13use crate::{ 17use crate::{
14 db::HirDatabase, 18 db::HirDatabase,
15 path::GenericArgs,
16 ty::primitive::{UncertainFloatTy, UncertainIntTy}, 19 ty::primitive::{UncertainFloatTy, UncertainIntTy},
17 type_ref::{Mutability, TypeRef},
18 DefWithBody, Either, HasSource, Name, Path, Resolver, Source, 20 DefWithBody, Either, HasSource, Name, Path, Resolver, Source,
19}; 21};
20 22
diff --git a/crates/ra_hir/src/expr/lower.rs b/crates/ra_hir/src/expr/lower.rs
index b3a9a2e6b..ad029b868 100644
--- a/crates/ra_hir/src/expr/lower.rs
+++ b/crates/ra_hir/src/expr/lower.rs
@@ -1,5 +1,10 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir_def::{
4 name::{self, AsName, Name},
5 path::GenericArgs,
6 type_ref::TypeRef,
7};
3use ra_arena::Arena; 8use ra_arena::Arena;
4use ra_syntax::{ 9use ra_syntax::{
5 ast::{ 10 ast::{
@@ -12,10 +17,7 @@ use test_utils::tested_by;
12 17
13use crate::{ 18use crate::{
14 db::HirDatabase, 19 db::HirDatabase,
15 name::{AsName, Name, SELF_PARAM},
16 path::GenericArgs,
17 ty::primitive::{FloatTy, IntTy, UncertainFloatTy, UncertainIntTy}, 20 ty::primitive::{FloatTy, IntTy, UncertainFloatTy, UncertainIntTy},
18 type_ref::TypeRef,
19 AstId, DefWithBody, Either, HirFileId, MacroCallLoc, MacroFileKind, Mutability, Path, Resolver, 21 AstId, DefWithBody, Either, HirFileId, MacroCallLoc, MacroFileKind, Mutability, Path, Resolver,
20 Source, 22 Source,
21}; 23};
@@ -78,7 +80,7 @@ where
78 let ptr = AstPtr::new(&self_param); 80 let ptr = AstPtr::new(&self_param);
79 let param_pat = self.alloc_pat( 81 let param_pat = self.alloc_pat(
80 Pat::Bind { 82 Pat::Bind {
81 name: SELF_PARAM, 83 name: name::SELF_PARAM,
82 mode: BindingAnnotation::Unannotated, 84 mode: BindingAnnotation::Unannotated,
83 subpat: None, 85 subpat: None,
84 }, 86 },
diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs
index 1aa853c3e..c685edda1 100644
--- a/crates/ra_hir/src/expr/validation.rs
+++ b/crates/ra_hir/src/expr/validation.rs
@@ -2,6 +2,7 @@
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use hir_def::path::known;
5use ra_syntax::ast; 6use ra_syntax::ast;
6use rustc_hash::FxHashSet; 7use rustc_hash::FxHashSet;
7 8
@@ -9,7 +10,6 @@ use crate::{
9 db::HirDatabase, 10 db::HirDatabase,
10 diagnostics::{DiagnosticSink, MissingFields, MissingOkInTailExpr}, 11 diagnostics::{DiagnosticSink, MissingFields, MissingOkInTailExpr},
11 expr::AstPtr, 12 expr::AstPtr,
12 path::known,
13 ty::{ApplicationTy, InferenceResult, Ty, TypeCtor}, 13 ty::{ApplicationTy, InferenceResult, Ty, TypeCtor},
14 Adt, Function, Name, Path, 14 Adt, Function, Name, Path,
15}; 15};
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index 93713bb14..b9fbaa367 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -1,16 +1,11 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use ra_db::{FileId, FilePosition}; 3use hir_def::name::AsName;
4use ra_syntax::{ 4use ra_syntax::ast::{self, AstNode, NameOwner};
5 algo::find_node_at_offset,
6 ast::{self, AstNode, NameOwner},
7 SyntaxNode,
8};
9 5
10use crate::{ 6use crate::{
11 db::{AstDatabase, DefDatabase, HirDatabase}, 7 db::{AstDatabase, DefDatabase, HirDatabase},
12 ids::{AstItemDef, LocationCtx}, 8 ids::{AstItemDef, LocationCtx},
13 name::AsName,
14 AstId, Const, Crate, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock, Module, 9 AstId, Const, Crate, Enum, EnumVariant, FieldSource, Function, HasSource, ImplBlock, Module,
15 ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union, VariantDef, 10 ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union, VariantDef,
16}; 11};
@@ -129,41 +124,6 @@ impl FromSource for StructField {
129 } 124 }
130} 125}
131 126
132// FIXME: simplify it
133impl ModuleSource {
134 pub fn from_position(
135 db: &(impl DefDatabase + AstDatabase),
136 position: FilePosition,
137 ) -> ModuleSource {
138 let parse = db.parse(position.file_id);
139 match &find_node_at_offset::<ast::Module>(parse.tree().syntax(), position.offset) {
140 Some(m) if !m.has_semi() => ModuleSource::Module(m.clone()),
141 _ => {
142 let source_file = parse.tree();
143 ModuleSource::SourceFile(source_file)
144 }
145 }
146 }
147
148 pub fn from_child_node(
149 db: &(impl DefDatabase + AstDatabase),
150 file_id: FileId,
151 child: &SyntaxNode,
152 ) -> ModuleSource {
153 if let Some(m) = child.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) {
154 ModuleSource::Module(m)
155 } else {
156 let source_file = db.parse(file_id).tree();
157 ModuleSource::SourceFile(source_file)
158 }
159 }
160
161 pub fn from_file_id(db: &(impl DefDatabase + AstDatabase), file_id: FileId) -> ModuleSource {
162 let source_file = db.parse(file_id).tree();
163 ModuleSource::SourceFile(source_file)
164 }
165}
166
167impl Module { 127impl Module {
168 pub fn from_declaration(db: &impl HirDatabase, src: Source<ast::Module>) -> Option<Self> { 128 pub fn from_declaration(db: &impl HirDatabase, src: Source<ast::Module>) -> Option<Self> {
169 let src_parent = Source { 129 let src_parent = Source {
diff --git a/crates/ra_hir/src/generics.rs b/crates/ra_hir/src/generics.rs
index 4ce7551c3..9d5d18564 100644
--- a/crates/ra_hir/src/generics.rs
+++ b/crates/ra_hir/src/generics.rs
@@ -5,15 +5,17 @@
5 5
6use std::sync::Arc; 6use std::sync::Arc;
7 7
8use hir_def::{
9 name::{self, AsName},
10 path::Path,
11 type_ref::{TypeBound, TypeRef},
12};
8use ra_syntax::ast::{self, DefaultTypeParamOwner, NameOwner, TypeBoundsOwner, TypeParamsOwner}; 13use ra_syntax::ast::{self, DefaultTypeParamOwner, NameOwner, TypeBoundsOwner, TypeParamsOwner};
9 14
10use crate::{ 15use crate::{
11 db::{AstDatabase, DefDatabase, HirDatabase}, 16 db::{AstDatabase, DefDatabase, HirDatabase},
12 name::SELF_TYPE, 17 Adt, Const, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct, Trait,
13 path::Path, 18 TypeAlias, Union,
14 type_ref::{TypeBound, TypeRef},
15 Adt, AsName, Const, Container, Enum, EnumVariant, Function, HasSource, ImplBlock, Name, Struct,
16 Trait, TypeAlias, Union,
17}; 19};
18 20
19/// Data about a generic parameter (to a function, struct, impl, ...). 21/// Data about a generic parameter (to a function, struct, impl, ...).
@@ -94,11 +96,15 @@ impl GenericParams {
94 GenericDef::Adt(Adt::Enum(it)) => generics.fill(&it.source(db).ast, start), 96 GenericDef::Adt(Adt::Enum(it)) => generics.fill(&it.source(db).ast, start),
95 GenericDef::Trait(it) => { 97 GenericDef::Trait(it) => {
96 // traits get the Self type as an implicit first type parameter 98 // traits get the Self type as an implicit first type parameter
97 generics.params.push(GenericParam { idx: start, name: SELF_TYPE, default: None }); 99 generics.params.push(GenericParam {
100 idx: start,
101 name: name::SELF_TYPE,
102 default: None,
103 });
98 generics.fill(&it.source(db).ast, start + 1); 104 generics.fill(&it.source(db).ast, start + 1);
99 // add super traits as bounds on Self 105 // add super traits as bounds on Self
100 // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar 106 // i.e., trait Foo: Bar is equivalent to trait Foo where Self: Bar
101 let self_param = TypeRef::Path(SELF_TYPE.into()); 107 let self_param = TypeRef::Path(name::SELF_TYPE.into());
102 generics.fill_bounds(&it.source(db).ast, self_param); 108 generics.fill_bounds(&it.source(db).ast, self_param);
103 } 109 }
104 GenericDef::TypeAlias(it) => generics.fill(&it.source(db).ast, start), 110 GenericDef::TypeAlias(it) => generics.fill(&it.source(db).ast, start),
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
index 06f21fc33..518330713 100644
--- a/crates/ra_hir/src/impl_block.rs
+++ b/crates/ra_hir/src/impl_block.rs
@@ -3,6 +3,7 @@
3use rustc_hash::FxHashMap; 3use rustc_hash::FxHashMap;
4use std::sync::Arc; 4use std::sync::Arc;
5 5
6use hir_def::{attr::Attr, type_ref::TypeRef};
6use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; 7use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
7use ra_cfg::CfgOptions; 8use ra_cfg::CfgOptions;
8use ra_syntax::{ 9use ra_syntax::{
@@ -11,7 +12,6 @@ use ra_syntax::{
11}; 12};
12 13
13use crate::{ 14use crate::{
14 attr::Attr,
15 code_model::{Module, ModuleSource}, 15 code_model::{Module, ModuleSource},
16 db::{AstDatabase, DefDatabase, HirDatabase}, 16 db::{AstDatabase, DefDatabase, HirDatabase},
17 generics::HasGenericParams, 17 generics::HasGenericParams,
@@ -19,7 +19,6 @@ use crate::{
19 ids::MacroCallLoc, 19 ids::MacroCallLoc,
20 resolve::Resolver, 20 resolve::Resolver,
21 ty::Ty, 21 ty::Ty,
22 type_ref::TypeRef,
23 AssocItem, AstId, Const, Function, HasSource, HirFileId, MacroFileKind, Path, Source, TraitRef, 22 AssocItem, AstId, Const, Function, HasSource, HirFileId, MacroFileKind, Path, Source, TraitRef,
24 TypeAlias, 23 TypeAlias,
25}; 24};
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index 0f2d233bb..f765490b0 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -26,24 +26,19 @@ macro_rules! impl_froms {
26 } 26 }
27} 27}
28 28
29mod either;
30pub mod debug; 29pub mod debug;
31 30
32pub mod db; 31pub mod db;
33#[macro_use] 32#[macro_use]
34pub mod mock; 33pub mod mock;
35mod path;
36pub mod source_binder; 34pub mod source_binder;
37 35
38mod ids; 36mod ids;
39mod name;
40mod nameres; 37mod nameres;
41mod adt; 38mod adt;
42mod traits; 39mod traits;
43mod type_alias; 40mod type_alias;
44mod type_ref;
45mod ty; 41mod ty;
46mod attr;
47mod impl_block; 42mod impl_block;
48mod expr; 43mod expr;
49mod lang_item; 44mod lang_item;
@@ -59,30 +54,23 @@ pub mod from_source;
59#[cfg(test)] 54#[cfg(test)]
60mod marks; 55mod marks;
61 56
62use hir_expand::{ 57use hir_expand::AstId;
63 ast_id_map::{AstIdMap, FileAstId},
64 AstId,
65};
66 58
67use crate::{ids::MacroFileKind, name::AsName, resolve::Resolver}; 59use crate::{ids::MacroFileKind, resolve::Resolver};
68 60
69pub use crate::{ 61pub use crate::{
70 adt::VariantDef, 62 adt::VariantDef,
71 either::Either,
72 expr::ExprScopes, 63 expr::ExprScopes,
73 from_source::FromSource, 64 from_source::FromSource,
74 generics::{GenericDef, GenericParam, GenericParams, HasGenericParams}, 65 generics::{GenericDef, GenericParam, GenericParams, HasGenericParams},
75 ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile}, 66 ids::{HirFileId, MacroCallId, MacroCallLoc, MacroDefId, MacroFile},
76 impl_block::ImplBlock, 67 impl_block::ImplBlock,
77 name::Name,
78 nameres::{ImportId, Namespace, PerNs}, 68 nameres::{ImportId, Namespace, PerNs},
79 path::{Path, PathKind},
80 resolve::ScopeDef, 69 resolve::ScopeDef,
81 source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, 70 source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer},
82 ty::{ 71 ty::{
83 display::HirDisplay, ApplicationTy, CallableDef, Substs, TraitRef, Ty, TypeCtor, TypeWalk, 72 display::HirDisplay, ApplicationTy, CallableDef, Substs, TraitRef, Ty, TypeCtor, TypeWalk,
84 }, 73 },
85 type_ref::Mutability,
86}; 74};
87 75
88pub use self::code_model::{ 76pub use self::code_model::{
@@ -92,3 +80,10 @@ pub use self::code_model::{
92 Enum, EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef, 80 Enum, EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef,
93 ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union, 81 ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
94}; 82};
83
84pub use hir_def::{
85 either::Either,
86 name::Name,
87 path::{Path, PathKind},
88 type_ref::Mutability,
89};
diff --git a/crates/ra_hir/src/marks.rs b/crates/ra_hir/src/marks.rs
index 79af24b20..b423489a1 100644
--- a/crates/ra_hir/src/marks.rs
+++ b/crates/ra_hir/src/marks.rs
@@ -2,6 +2,7 @@
2 2
3test_utils::marks!( 3test_utils::marks!(
4 bogus_paths 4 bogus_paths
5 // FIXME: restore this mark once hir is split
5 name_res_works_for_broken_modules 6 name_res_works_for_broken_modules
6 can_import_enum_variant 7 can_import_enum_variant
7 type_var_cycles_resolve_completely 8 type_var_cycles_resolve_completely
diff --git a/crates/ra_hir/src/mock.rs b/crates/ra_hir/src/mock.rs
index 0b278deb3..35dfaf3ba 100644
--- a/crates/ra_hir/src/mock.rs
+++ b/crates/ra_hir/src/mock.rs
@@ -22,6 +22,7 @@ pub const WORKSPACE: SourceRootId = SourceRootId(0);
22 db::InternDatabaseStorage, 22 db::InternDatabaseStorage,
23 db::AstDatabaseStorage, 23 db::AstDatabaseStorage,
24 db::DefDatabaseStorage, 24 db::DefDatabaseStorage,
25 db::DefDatabase2Storage,
25 db::HirDatabaseStorage 26 db::HirDatabaseStorage
26)] 27)]
27#[derive(Debug)] 28#[derive(Debug)]
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index b325979f5..39f585b44 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -48,7 +48,6 @@
48//! on the result 48//! on the result
49 49
50mod per_ns; 50mod per_ns;
51mod raw;
52mod collector; 51mod collector;
53mod mod_resolution; 52mod mod_resolution;
54#[cfg(test)] 53#[cfg(test)]
@@ -74,12 +73,9 @@ use crate::{
74 Trait, 73 Trait,
75}; 74};
76 75
77pub(crate) use self::raw::{ImportSourceMap, RawItems}; 76pub use self::per_ns::{Namespace, PerNs};
78 77
79pub use self::{ 78pub use hir_def::nameres::raw::ImportId;
80 per_ns::{Namespace, PerNs},
81 raw::ImportId,
82};
83 79
84/// Contains all top-level defs from a macro-expanded crate 80/// Contains all top-level defs from a macro-expanded crate
85#[derive(Debug, PartialEq, Eq)] 81#[derive(Debug, PartialEq, Eq)]
@@ -328,7 +324,8 @@ impl CrateDefMap {
328 ) -> ResolvePathResult { 324 ) -> ResolvePathResult {
329 let mut segments = path.segments.iter().enumerate(); 325 let mut segments = path.segments.iter().enumerate();
330 let mut curr_per_ns: PerNs = match path.kind { 326 let mut curr_per_ns: PerNs = match path.kind {
331 PathKind::DollarCrate(krate) => { 327 PathKind::DollarCrate(crate_id) => {
328 let krate = Crate { crate_id };
332 if krate == self.krate { 329 if krate == self.krate {
333 tested_by!(macro_dollar_crate_self); 330 tested_by!(macro_dollar_crate_self);
334 PerNs::types(Module::new(self.krate, self.root).into()) 331 PerNs::types(Module::new(self.krate, self.root).into())
diff --git a/crates/ra_hir/src/nameres/collector.rs b/crates/ra_hir/src/nameres/collector.rs
index a94a0554c..2f342870b 100644
--- a/crates/ra_hir/src/nameres/collector.rs
+++ b/crates/ra_hir/src/nameres/collector.rs
@@ -1,5 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir_def::{attr::Attr, name, nameres::raw};
3use ra_cfg::CfgOptions; 4use ra_cfg::CfgOptions;
4use ra_db::FileId; 5use ra_db::FileId;
5use ra_syntax::{ast, SmolStr}; 6use ra_syntax::{ast, SmolStr};
@@ -7,12 +8,10 @@ use rustc_hash::FxHashMap;
7use test_utils::tested_by; 8use test_utils::tested_by;
8 9
9use crate::{ 10use crate::{
10 attr::Attr,
11 db::DefDatabase, 11 db::DefDatabase,
12 ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind}, 12 ids::{AstItemDef, LocationCtx, MacroCallId, MacroCallLoc, MacroDefId, MacroFileKind},
13 name::MACRO_RULES,
14 nameres::{ 13 nameres::{
15 diagnostics::DefDiagnostic, mod_resolution::ModDir, raw, Crate, CrateDefMap, CrateModuleId, 14 diagnostics::DefDiagnostic, mod_resolution::ModDir, Crate, CrateDefMap, CrateModuleId,
16 ModuleData, ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode, 15 ModuleData, ModuleDef, PerNs, ReachedFixedPoint, Resolution, ResolveMode,
17 }, 16 },
18 Adt, AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind, Static, 17 Adt, AstId, Const, Enum, Function, HirFileId, MacroDef, Module, Name, Path, PathKind, Static,
@@ -725,7 +724,7 @@ where
725} 724}
726 725
727fn is_macro_rules(path: &Path) -> bool { 726fn is_macro_rules(path: &Path) -> bool {
728 path.as_ident() == Some(&MACRO_RULES) 727 path.as_ident() == Some(&name::MACRO_RULES)
729} 728}
730 729
731#[cfg(test)] 730#[cfg(test)]
diff --git a/crates/ra_hir/src/nameres/tests/mod_resolution.rs b/crates/ra_hir/src/nameres/tests/mod_resolution.rs
index f569aacdc..abfe8b1c3 100644
--- a/crates/ra_hir/src/nameres/tests/mod_resolution.rs
+++ b/crates/ra_hir/src/nameres/tests/mod_resolution.rs
@@ -2,7 +2,7 @@ use super::*;
2 2
3#[test] 3#[test]
4fn name_res_works_for_broken_modules() { 4fn name_res_works_for_broken_modules() {
5 covers!(name_res_works_for_broken_modules); 5 // covers!(name_res_works_for_broken_modules);
6 let map = def_map( 6 let map = def_map(
7 " 7 "
8 //- /lib.rs 8 //- /lib.rs
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs
index 8b6269407..2a783b61e 100644
--- a/crates/ra_hir/src/resolve.rs
+++ b/crates/ra_hir/src/resolve.rs
@@ -1,7 +1,11 @@
1//! Name resolution. 1//! Name resolution.
2use std::sync::Arc; 2use std::sync::Arc;
3 3
4use hir_def::CrateModuleId; 4use hir_def::{
5 name::{self, Name},
6 path::{Path, PathKind},
7 CrateModuleId,
8};
5use rustc_hash::FxHashSet; 9use rustc_hash::FxHashSet;
6 10
7use crate::{ 11use crate::{
@@ -13,9 +17,7 @@ use crate::{
13 }, 17 },
14 generics::GenericParams, 18 generics::GenericParams,
15 impl_block::ImplBlock, 19 impl_block::ImplBlock,
16 name::{Name, SELF_PARAM, SELF_TYPE},
17 nameres::{CrateDefMap, PerNs}, 20 nameres::{CrateDefMap, PerNs},
18 path::{Path, PathKind},
19 Adt, BuiltinType, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, Static, Struct, 21 Adt, BuiltinType, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, Static, Struct,
20 Trait, TypeAlias, 22 Trait, TypeAlias,
21}; 23};
@@ -150,13 +152,13 @@ impl Resolver {
150 } 152 }
151 } 153 }
152 Scope::ImplBlockScope(impl_) => { 154 Scope::ImplBlockScope(impl_) => {
153 if first_name == &SELF_TYPE { 155 if first_name == &name::SELF_TYPE {
154 let idx = if path.segments.len() == 1 { None } else { Some(1) }; 156 let idx = if path.segments.len() == 1 { None } else { Some(1) };
155 return Some((TypeNs::SelfType(*impl_), idx)); 157 return Some((TypeNs::SelfType(*impl_), idx));
156 } 158 }
157 } 159 }
158 Scope::AdtScope(adt) => { 160 Scope::AdtScope(adt) => {
159 if first_name == &SELF_TYPE { 161 if first_name == &name::SELF_TYPE {
160 let idx = if path.segments.len() == 1 { None } else { Some(1) }; 162 let idx = if path.segments.len() == 1 { None } else { Some(1) };
161 return Some((TypeNs::AdtSelfType(*adt), idx)); 163 return Some((TypeNs::AdtSelfType(*adt), idx));
162 } 164 }
@@ -205,7 +207,7 @@ impl Resolver {
205 return None; 207 return None;
206 } 208 }
207 let n_segments = path.segments.len(); 209 let n_segments = path.segments.len();
208 let tmp = SELF_PARAM; 210 let tmp = name::SELF_PARAM;
209 let first_name = if path.is_self() { &tmp } else { &path.segments.first()?.name }; 211 let first_name = if path.is_self() { &tmp } else { &path.segments.first()?.name };
210 let skip_to_mod = path.kind != PathKind::Plain && !path.is_self(); 212 let skip_to_mod = path.kind != PathKind::Plain && !path.is_self();
211 for scope in self.scopes.iter().rev() { 213 for scope in self.scopes.iter().rev() {
@@ -241,13 +243,13 @@ impl Resolver {
241 Scope::GenericParams(_) => continue, 243 Scope::GenericParams(_) => continue,
242 244
243 Scope::ImplBlockScope(impl_) if n_segments > 1 => { 245 Scope::ImplBlockScope(impl_) if n_segments > 1 => {
244 if first_name == &SELF_TYPE { 246 if first_name == &name::SELF_TYPE {
245 let ty = TypeNs::SelfType(*impl_); 247 let ty = TypeNs::SelfType(*impl_);
246 return Some(ResolveValueResult::Partial(ty, 1)); 248 return Some(ResolveValueResult::Partial(ty, 1));
247 } 249 }
248 } 250 }
249 Scope::AdtScope(adt) if n_segments > 1 => { 251 Scope::AdtScope(adt) if n_segments > 1 => {
250 if first_name == &SELF_TYPE { 252 if first_name == &name::SELF_TYPE {
251 let ty = TypeNs::AdtSelfType(*adt); 253 let ty = TypeNs::AdtSelfType(*adt);
252 return Some(ResolveValueResult::Partial(ty, 1)); 254 return Some(ResolveValueResult::Partial(ty, 1));
253 } 255 }
@@ -459,10 +461,10 @@ impl Scope {
459 } 461 }
460 } 462 }
461 Scope::ImplBlockScope(i) => { 463 Scope::ImplBlockScope(i) => {
462 f(SELF_TYPE, ScopeDef::ImplSelfType(*i)); 464 f(name::SELF_TYPE, ScopeDef::ImplSelfType(*i));
463 } 465 }
464 Scope::AdtScope(i) => { 466 Scope::AdtScope(i) => {
465 f(SELF_TYPE, ScopeDef::AdtSelfType(*i)); 467 f(name::SELF_TYPE, ScopeDef::AdtSelfType(*i));
466 } 468 }
467 Scope::ExprScope(e) => { 469 Scope::ExprScope(e) => {
468 e.expr_scopes.entries(e.scope_id).iter().for_each(|e| { 470 e.expr_scopes.entries(e.scope_id).iter().for_each(|e| {
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 730c33226..544433a0a 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -7,6 +7,7 @@
7//! purely for "IDE needs". 7//! purely for "IDE needs".
8use std::sync::Arc; 8use std::sync::Arc;
9 9
10use hir_def::{name::AsName, path::known};
10use ra_db::FileId; 11use ra_db::FileId;
11use ra_syntax::{ 12use ra_syntax::{
12 ast::{self, AstNode}, 13 ast::{self, AstNode},
@@ -24,11 +25,10 @@ use crate::{
24 BodySourceMap, 25 BodySourceMap,
25 }, 26 },
26 ids::LocationCtx, 27 ids::LocationCtx,
27 path::known,
28 resolve::{ScopeDef, TypeNs, ValueNs}, 28 resolve::{ScopeDef, TypeNs, ValueNs},
29 ty::method_resolution::implements_trait, 29 ty::method_resolution::implements_trait,
30 AsName, Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, MacroDef, 30 Const, DefWithBody, Either, Enum, FromSource, Function, HasBody, HirFileId, MacroDef, Module,
31 Module, Name, Path, Resolver, Static, Struct, Ty, 31 Name, Path, Resolver, Static, Struct, Ty,
32}; 32};
33 33
34fn try_get_resolver_for_node( 34fn try_get_resolver_for_node(
diff --git a/crates/ra_hir/src/traits.rs b/crates/ra_hir/src/traits.rs
index 22f188049..514c813ab 100644
--- a/crates/ra_hir/src/traits.rs
+++ b/crates/ra_hir/src/traits.rs
@@ -1,14 +1,14 @@
1//! HIR for trait definitions. 1//! HIR for trait definitions.
2 2
3use rustc_hash::FxHashMap;
4use std::sync::Arc; 3use std::sync::Arc;
5 4
5use hir_def::name::AsName;
6use ra_syntax::ast::{self, NameOwner}; 6use ra_syntax::ast::{self, NameOwner};
7use rustc_hash::FxHashMap;
7 8
8use crate::{ 9use crate::{
9 db::{AstDatabase, DefDatabase}, 10 db::{AstDatabase, DefDatabase},
10 ids::LocationCtx, 11 ids::LocationCtx,
11 name::AsName,
12 AssocItem, Const, Function, HasSource, Module, Name, Trait, TypeAlias, 12 AssocItem, Const, Function, HasSource, Module, Name, Trait, TypeAlias,
13}; 13};
14 14
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index cc9746f6d..d2bfcdc7d 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -17,8 +17,8 @@ use std::sync::Arc;
17use std::{fmt, iter, mem}; 17use std::{fmt, iter, mem};
18 18
19use crate::{ 19use crate::{
20 db::HirDatabase, expr::ExprId, type_ref::Mutability, util::make_mut_slice, Adt, Crate, 20 db::HirDatabase, expr::ExprId, util::make_mut_slice, Adt, Crate, DefWithBody, GenericParams,
21 DefWithBody, GenericParams, HasGenericParams, Name, Trait, TypeAlias, 21 HasGenericParams, Mutability, Name, Trait, TypeAlias,
22}; 22};
23use display::{HirDisplay, HirFormatter}; 23use display::{HirDisplay, HirFormatter};
24 24
diff --git a/crates/ra_hir/src/ty/autoderef.rs b/crates/ra_hir/src/ty/autoderef.rs
index 02492ca14..03c45546d 100644
--- a/crates/ra_hir/src/ty/autoderef.rs
+++ b/crates/ra_hir/src/ty/autoderef.rs
@@ -5,10 +5,11 @@
5 5
6use std::iter::successors; 6use std::iter::successors;
7 7
8use hir_def::name;
8use log::{info, warn}; 9use log::{info, warn};
9 10
10use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk}; 11use super::{traits::Solution, Canonical, Substs, Ty, TypeWalk};
11use crate::{db::HirDatabase, name, HasGenericParams, Resolver}; 12use crate::{db::HirDatabase, HasGenericParams, Resolver};
12 13
13const AUTODEREF_RECURSION_LIMIT: usize = 10; 14const AUTODEREF_RECURSION_LIMIT: usize = 10;
14 15
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs
index ebaff998e..7466ee341 100644
--- a/crates/ra_hir/src/ty/infer.rs
+++ b/crates/ra_hir/src/ty/infer.rs
@@ -21,6 +21,11 @@ use std::sync::Arc;
21use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; 21use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
22use rustc_hash::FxHashMap; 22use rustc_hash::FxHashMap;
23 23
24use hir_def::{
25 name,
26 path::known,
27 type_ref::{Mutability, TypeRef},
28};
24use ra_arena::map::ArenaMap; 29use ra_arena::map::ArenaMap;
25use ra_prof::profile; 30use ra_prof::profile;
26use test_utils::tested_by; 31use test_utils::tested_by;
@@ -37,11 +42,8 @@ use crate::{
37 db::HirDatabase, 42 db::HirDatabase,
38 diagnostics::DiagnosticSink, 43 diagnostics::DiagnosticSink,
39 expr::{BindingAnnotation, Body, ExprId, PatId}, 44 expr::{BindingAnnotation, Body, ExprId, PatId},
40 name,
41 path::known,
42 resolve::{Resolver, TypeNs}, 45 resolve::{Resolver, TypeNs},
43 ty::infer::diagnostics::InferenceDiagnostic, 46 ty::infer::diagnostics::InferenceDiagnostic,
44 type_ref::{Mutability, TypeRef},
45 Adt, AssocItem, ConstData, DefWithBody, FnData, Function, HasBody, Path, StructField, 47 Adt, AssocItem, ConstData, DefWithBody, FnData, Function, HasBody, Path, StructField,
46}; 48};
47 49
diff --git a/crates/ra_hir/src/ty/infer/coerce.rs b/crates/ra_hir/src/ty/infer/coerce.rs
index 0429a9866..6ea135126 100644
--- a/crates/ra_hir/src/ty/infer/coerce.rs
+++ b/crates/ra_hir/src/ty/infer/coerce.rs
@@ -14,8 +14,7 @@ use crate::{
14 lang_item::LangItemTarget, 14 lang_item::LangItemTarget,
15 resolve::Resolver, 15 resolve::Resolver,
16 ty::{autoderef, Substs, Ty, TypeCtor, TypeWalk}, 16 ty::{autoderef, Substs, Ty, TypeCtor, TypeWalk},
17 type_ref::Mutability, 17 Adt, Mutability,
18 Adt,
19}; 18};
20 19
21impl<'a, D: HirDatabase> InferenceContext<'a, D> { 20impl<'a, D: HirDatabase> InferenceContext<'a, D> {
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs
index f8807c742..bc6437b44 100644
--- a/crates/ra_hir/src/ty/infer/expr.rs
+++ b/crates/ra_hir/src/ty/infer/expr.rs
@@ -3,14 +3,17 @@
3use std::iter::{repeat, repeat_with}; 3use std::iter::{repeat, repeat_with};
4use std::sync::Arc; 4use std::sync::Arc;
5 5
6use hir_def::{
7 name,
8 path::{GenericArg, GenericArgs},
9};
10
6use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; 11use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch};
7use crate::{ 12use crate::{
8 db::HirDatabase, 13 db::HirDatabase,
9 expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, 14 expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp},
10 generics::{GenericParams, HasGenericParams}, 15 generics::{GenericParams, HasGenericParams},
11 name,
12 nameres::Namespace, 16 nameres::Namespace,
13 path::{GenericArg, GenericArgs},
14 ty::{ 17 ty::{
15 autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Obligation, 18 autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Obligation,
16 ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, 19 ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk,
diff --git a/crates/ra_hir/src/ty/infer/path.rs b/crates/ra_hir/src/ty/infer/path.rs
index db979353a..77aa35ce1 100644
--- a/crates/ra_hir/src/ty/infer/path.rs
+++ b/crates/ra_hir/src/ty/infer/path.rs
@@ -1,5 +1,7 @@
1//! Path expression resolution. 1//! Path expression resolution.
2 2
3use hir_def::path::PathSegment;
4
3use super::{ExprOrPatId, InferenceContext, TraitRef}; 5use super::{ExprOrPatId, InferenceContext, TraitRef};
4use crate::{ 6use crate::{
5 db::HirDatabase, 7 db::HirDatabase,
@@ -131,7 +133,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
131 fn resolve_trait_assoc_item( 133 fn resolve_trait_assoc_item(
132 &mut self, 134 &mut self,
133 trait_ref: TraitRef, 135 trait_ref: TraitRef,
134 segment: &crate::path::PathSegment, 136 segment: &PathSegment,
135 id: ExprOrPatId, 137 id: ExprOrPatId,
136 ) -> Option<(ValueNs, Option<Substs>)> { 138 ) -> Option<(ValueNs, Option<Substs>)> {
137 let trait_ = trait_ref.trait_; 139 let trait_ = trait_ref.trait_;
@@ -170,7 +172,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
170 fn resolve_ty_assoc_item( 172 fn resolve_ty_assoc_item(
171 &mut self, 173 &mut self,
172 ty: Ty, 174 ty: Ty,
173 segment: &crate::path::PathSegment, 175 segment: &PathSegment,
174 id: ExprOrPatId, 176 id: ExprOrPatId,
175 ) -> Option<(ValueNs, Option<Substs>)> { 177 ) -> Option<(ValueNs, Option<Substs>)> {
176 if let Ty::Unknown = ty { 178 if let Ty::Unknown = ty {
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index 366556134..0f49a0e54 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -8,6 +8,11 @@
8use std::iter; 8use std::iter;
9use std::sync::Arc; 9use std::sync::Arc;
10 10
11use hir_def::{
12 path::{GenericArg, PathSegment},
13 type_ref::{TypeBound, TypeRef},
14};
15
11use super::{ 16use super::{
12 FnSig, GenericPredicate, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, 17 FnSig, GenericPredicate, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor,
13 TypeWalk, 18 TypeWalk,
@@ -18,10 +23,8 @@ use crate::{
18 generics::HasGenericParams, 23 generics::HasGenericParams,
19 generics::{GenericDef, WherePredicate}, 24 generics::{GenericDef, WherePredicate},
20 nameres::Namespace, 25 nameres::Namespace,
21 path::{GenericArg, PathSegment},
22 resolve::{Resolver, TypeNs}, 26 resolve::{Resolver, TypeNs},
23 ty::Adt, 27 ty::Adt,
24 type_ref::{TypeBound, TypeRef},
25 util::make_mut_slice, 28 util::make_mut_slice,
26 BuiltinType, Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, 29 BuiltinType, Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField,
27 Trait, TypeAlias, Union, 30 Trait, TypeAlias, Union,
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs
index 50583a142..eb69344f6 100644
--- a/crates/ra_hir/src/ty/method_resolution.rs
+++ b/crates/ra_hir/src/ty/method_resolution.rs
@@ -15,8 +15,7 @@ use crate::{
15 resolve::Resolver, 15 resolve::Resolver,
16 ty::primitive::{FloatBitness, UncertainFloatTy, UncertainIntTy}, 16 ty::primitive::{FloatBitness, UncertainFloatTy, UncertainIntTy},
17 ty::{Ty, TypeCtor}, 17 ty::{Ty, TypeCtor},
18 type_ref::Mutability, 18 AssocItem, Crate, Function, Module, Mutability, Name, Trait,
19 AssocItem, Crate, Function, Module, Name, Trait,
20}; 19};
21 20
22/// This is used as a key for indexing impls. 21/// This is used as a key for indexing impls.
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs
index ab66515be..2dd4c2fae 100644
--- a/crates/ra_hir/src/ty/traits/chalk.rs
+++ b/crates/ra_hir/src/ty/traits/chalk.rs
@@ -9,6 +9,7 @@ use chalk_ir::{
9}; 9};
10use chalk_rust_ir::{AssociatedTyDatum, ImplDatum, StructDatum, TraitDatum}; 10use chalk_rust_ir::{AssociatedTyDatum, ImplDatum, StructDatum, TraitDatum};
11 11
12use hir_def::name;
12use ra_db::salsa::{InternId, InternKey}; 13use ra_db::salsa::{InternId, InternKey};
13 14
14use super::{Canonical, ChalkContext, Impl, Obligation}; 15use super::{Canonical, ChalkContext, Impl, Obligation};
@@ -734,7 +735,7 @@ fn closure_fn_trait_impl_datum(
734 substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(), 735 substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(),
735 }; 736 };
736 737
737 let output_ty_id = fn_once_trait.associated_type_by_name(db, &crate::name::OUTPUT_TYPE)?; 738 let output_ty_id = fn_once_trait.associated_type_by_name(db, &name::OUTPUT_TYPE)?;
738 739
739 let output_ty_value = chalk_rust_ir::AssociatedTyValue { 740 let output_ty_value = chalk_rust_ir::AssociatedTyValue {
740 associated_ty_id: output_ty_id.to_chalk(db), 741 associated_ty_id: output_ty_id.to_chalk(db),
diff --git a/crates/ra_hir/src/type_alias.rs b/crates/ra_hir/src/type_alias.rs
index 674a46102..87126ee7f 100644
--- a/crates/ra_hir/src/type_alias.rs
+++ b/crates/ra_hir/src/type_alias.rs
@@ -2,12 +2,14 @@
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use hir_def::{
6 name::{AsName, Name},
7 type_ref::TypeRef,
8};
5use ra_syntax::ast::NameOwner; 9use ra_syntax::ast::NameOwner;
6 10
7use crate::{ 11use crate::{
8 db::{AstDatabase, DefDatabase}, 12 db::{AstDatabase, DefDatabase},
9 name::{AsName, Name},
10 type_ref::TypeRef,
11 HasSource, TypeAlias, 13 HasSource, TypeAlias,
12}; 14};
13 15
diff --git a/crates/ra_hir_def/Cargo.toml b/crates/ra_hir_def/Cargo.toml
index 75e93f254..746c907e8 100644
--- a/crates/ra_hir_def/Cargo.toml
+++ b/crates/ra_hir_def/Cargo.toml
@@ -6,9 +6,16 @@ authors = ["rust-analyzer developers"]
6 6
7[dependencies] 7[dependencies]
8log = "0.4.5" 8log = "0.4.5"
9once_cell = "1.0.1"
10relative-path = "1.0.0"
11rustc-hash = "1.0"
9 12
10ra_arena = { path = "../ra_arena" } 13ra_arena = { path = "../ra_arena" }
11ra_db = { path = "../ra_db" } 14ra_db = { path = "../ra_db" }
12ra_syntax = { path = "../ra_syntax" } 15ra_syntax = { path = "../ra_syntax" }
13ra_prof = { path = "../ra_prof" } 16ra_prof = { path = "../ra_prof" }
14hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" } 17hir_expand = { path = "../ra_hir_expand", package = "ra_hir_expand" }
18test_utils = { path = "../test_utils" }
19mbe = { path = "../ra_mbe", package = "ra_mbe" }
20ra_cfg = { path = "../ra_cfg" }
21tt = { path = "../ra_tt", package = "ra_tt" }
diff --git a/crates/ra_hir/src/attr.rs b/crates/ra_hir_def/src/attr.rs
index bd159a566..248f03cdf 100644
--- a/crates/ra_hir/src/attr.rs
+++ b/crates/ra_hir_def/src/attr.rs
@@ -2,6 +2,7 @@
2 2
3use std::sync::Arc; 3use std::sync::Arc;
4 4
5use hir_expand::db::AstDatabase;
5use mbe::ast_to_token_tree; 6use mbe::ast_to_token_tree;
6use ra_cfg::CfgOptions; 7use ra_cfg::CfgOptions;
7use ra_syntax::{ 8use ra_syntax::{
@@ -10,10 +11,10 @@ use ra_syntax::{
10}; 11};
11use tt::Subtree; 12use tt::Subtree;
12 13
13use crate::{db::AstDatabase, path::Path, HirFileId, Source}; 14use crate::{path::Path, HirFileId, Source};
14 15
15#[derive(Debug, Clone, PartialEq, Eq)] 16#[derive(Debug, Clone, PartialEq, Eq)]
16pub(crate) struct Attr { 17pub struct Attr {
17 pub(crate) path: Path, 18 pub(crate) path: Path,
18 pub(crate) input: Option<AttrInput>, 19 pub(crate) input: Option<AttrInput>,
19} 20}
@@ -45,7 +46,7 @@ impl Attr {
45 Some(Attr { path, input }) 46 Some(Attr { path, input })
46 } 47 }
47 48
48 pub(crate) fn from_attrs_owner( 49 pub fn from_attrs_owner(
49 file_id: HirFileId, 50 file_id: HirFileId,
50 owner: &dyn AttrsOwner, 51 owner: &dyn AttrsOwner,
51 db: &impl AstDatabase, 52 db: &impl AstDatabase,
@@ -58,13 +59,13 @@ impl Attr {
58 Some(attrs.flat_map(|ast| Attr::from_src(Source { file_id, ast }, db)).collect()) 59 Some(attrs.flat_map(|ast| Attr::from_src(Source { file_id, ast }, db)).collect())
59 } 60 }
60 61
61 pub(crate) fn is_simple_atom(&self, name: &str) -> bool { 62 pub fn is_simple_atom(&self, name: &str) -> bool {
62 // FIXME: Avoid cloning 63 // FIXME: Avoid cloning
63 self.path.as_ident().map_or(false, |s| s.to_string() == name) 64 self.path.as_ident().map_or(false, |s| s.to_string() == name)
64 } 65 }
65 66
66 // FIXME: handle cfg_attr :-) 67 // FIXME: handle cfg_attr :-)
67 pub(crate) fn as_cfg(&self) -> Option<&Subtree> { 68 pub fn as_cfg(&self) -> Option<&Subtree> {
68 if !self.is_simple_atom("cfg") { 69 if !self.is_simple_atom("cfg") {
69 return None; 70 return None;
70 } 71 }
@@ -74,7 +75,7 @@ impl Attr {
74 } 75 }
75 } 76 }
76 77
77 pub(crate) fn as_path(&self) -> Option<&SmolStr> { 78 pub fn as_path(&self) -> Option<&SmolStr> {
78 if !self.is_simple_atom("path") { 79 if !self.is_simple_atom("path") {
79 return None; 80 return None;
80 } 81 }
@@ -84,7 +85,7 @@ impl Attr {
84 } 85 }
85 } 86 }
86 87
87 pub(crate) fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> Option<bool> { 88 pub fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> Option<bool> {
88 cfg_options.is_cfg_enabled(self.as_cfg()?) 89 cfg_options.is_cfg_enabled(self.as_cfg()?)
89 } 90 }
90} 91}
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs
index f6f976c86..b271636b0 100644
--- a/crates/ra_hir_def/src/db.rs
+++ b/crates/ra_hir_def/src/db.rs
@@ -1,8 +1,12 @@
1//! Defines database & queries for name resolution. 1//! Defines database & queries for name resolution.
2use std::sync::Arc;
2 3
4use hir_expand::{db::AstDatabase, HirFileId};
3use ra_db::{salsa, SourceDatabase}; 5use ra_db::{salsa, SourceDatabase};
4use ra_syntax::ast; 6use ra_syntax::ast;
5 7
8use crate::nameres::raw::{ImportSourceMap, RawItems};
9
6#[salsa::query_group(InternDatabaseStorage)] 10#[salsa::query_group(InternDatabaseStorage)]
7pub trait InternDatabase: SourceDatabase { 11pub trait InternDatabase: SourceDatabase {
8 #[salsa::interned] 12 #[salsa::interned]
@@ -10,6 +14,8 @@ pub trait InternDatabase: SourceDatabase {
10 #[salsa::interned] 14 #[salsa::interned]
11 fn intern_struct(&self, loc: crate::ItemLoc<ast::StructDef>) -> crate::StructId; 15 fn intern_struct(&self, loc: crate::ItemLoc<ast::StructDef>) -> crate::StructId;
12 #[salsa::interned] 16 #[salsa::interned]
17 fn intern_union(&self, loc: crate::ItemLoc<ast::StructDef>) -> crate::UnionId;
18 #[salsa::interned]
13 fn intern_enum(&self, loc: crate::ItemLoc<ast::EnumDef>) -> crate::EnumId; 19 fn intern_enum(&self, loc: crate::ItemLoc<ast::EnumDef>) -> crate::EnumId;
14 #[salsa::interned] 20 #[salsa::interned]
15 fn intern_const(&self, loc: crate::ItemLoc<ast::ConstDef>) -> crate::ConstId; 21 fn intern_const(&self, loc: crate::ItemLoc<ast::ConstDef>) -> crate::ConstId;
@@ -20,3 +26,15 @@ pub trait InternDatabase: SourceDatabase {
20 #[salsa::interned] 26 #[salsa::interned]
21 fn intern_type_alias(&self, loc: crate::ItemLoc<ast::TypeAliasDef>) -> crate::TypeAliasId; 27 fn intern_type_alias(&self, loc: crate::ItemLoc<ast::TypeAliasDef>) -> crate::TypeAliasId;
22} 28}
29
30#[salsa::query_group(DefDatabase2Storage)]
31pub trait DefDatabase2: InternDatabase + AstDatabase {
32 #[salsa::invoke(RawItems::raw_items_with_source_map_query)]
33 fn raw_items_with_source_map(
34 &self,
35 file_id: HirFileId,
36 ) -> (Arc<RawItems>, Arc<ImportSourceMap>);
37
38 #[salsa::invoke(RawItems::raw_items_query)]
39 fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>;
40}
diff --git a/crates/ra_hir/src/either.rs b/crates/ra_hir_def/src/either.rs
index 83583ef8b..83583ef8b 100644
--- a/crates/ra_hir/src/either.rs
+++ b/crates/ra_hir_def/src/either.rs
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 4d6b9db03..95d503325 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -8,12 +8,20 @@
8//! actually true. 8//! actually true.
9 9
10pub mod db; 10pub mod db;
11pub mod either;
12pub mod attr;
13pub mod name;
14pub mod path;
15pub mod type_ref;
16
17// FIXME: this should be private
18pub mod nameres;
11 19
12use std::hash::{Hash, Hasher}; 20use std::hash::{Hash, Hasher};
13 21
14use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId}; 22use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId};
15use ra_arena::{impl_arena_id, RawId}; 23use ra_arena::{impl_arena_id, RawId};
16use ra_db::{salsa, CrateId}; 24use ra_db::{salsa, CrateId, FileId};
17use ra_syntax::{ast, AstNode, SyntaxNode}; 25use ra_syntax::{ast, AstNode, SyntaxNode};
18 26
19use crate::db::InternDatabase; 27use crate::db::InternDatabase;
@@ -24,6 +32,68 @@ pub struct Source<T> {
24 pub ast: T, 32 pub ast: T,
25} 33}
26 34
35pub enum ModuleSource {
36 SourceFile(ast::SourceFile),
37 Module(ast::Module),
38}
39
40impl ModuleSource {
41 pub fn new(
42 db: &impl db::DefDatabase2,
43 file_id: Option<FileId>,
44 decl_id: Option<AstId<ast::Module>>,
45 ) -> ModuleSource {
46 match (file_id, decl_id) {
47 (Some(file_id), _) => {
48 let source_file = db.parse(file_id).tree();
49 ModuleSource::SourceFile(source_file)
50 }
51 (None, Some(item_id)) => {
52 let module = item_id.to_node(db);
53 assert!(module.item_list().is_some(), "expected inline module");
54 ModuleSource::Module(module)
55 }
56 (None, None) => panic!(),
57 }
58 }
59
60 // FIXME: this methods do not belong here
61 pub fn from_position(
62 db: &impl db::DefDatabase2,
63 position: ra_db::FilePosition,
64 ) -> ModuleSource {
65 let parse = db.parse(position.file_id);
66 match &ra_syntax::algo::find_node_at_offset::<ast::Module>(
67 parse.tree().syntax(),
68 position.offset,
69 ) {
70 Some(m) if !m.has_semi() => ModuleSource::Module(m.clone()),
71 _ => {
72 let source_file = parse.tree();
73 ModuleSource::SourceFile(source_file)
74 }
75 }
76 }
77
78 pub fn from_child_node(
79 db: &impl db::DefDatabase2,
80 file_id: FileId,
81 child: &SyntaxNode,
82 ) -> ModuleSource {
83 if let Some(m) = child.ancestors().filter_map(ast::Module::cast).find(|it| !it.has_semi()) {
84 ModuleSource::Module(m)
85 } else {
86 let source_file = db.parse(file_id).tree();
87 ModuleSource::SourceFile(source_file)
88 }
89 }
90
91 pub fn from_file_id(db: &impl db::DefDatabase2, file_id: FileId) -> ModuleSource {
92 let source_file = db.parse(file_id).tree();
93 ModuleSource::SourceFile(source_file)
94 }
95}
96
27impl<T> Source<T> { 97impl<T> Source<T> {
28 pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> { 98 pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> {
29 Source { file_id: self.file_id, ast: f(self.ast) } 99 Source { file_id: self.file_id, ast: f(self.ast) }
@@ -156,6 +226,18 @@ impl AstItemDef<ast::StructDef> for StructId {
156} 226}
157 227
158#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 228#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
229pub struct UnionId(salsa::InternId);
230impl_intern_key!(UnionId);
231impl AstItemDef<ast::StructDef> for UnionId {
232 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::StructDef>) -> Self {
233 db.intern_union(loc)
234 }
235 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::StructDef> {
236 db.lookup_intern_union(self)
237 }
238}
239
240#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
159pub struct EnumId(salsa::InternId); 241pub struct EnumId(salsa::InternId);
160impl_intern_key!(EnumId); 242impl_intern_key!(EnumId);
161impl AstItemDef<ast::EnumDef> for EnumId { 243impl AstItemDef<ast::EnumDef> for EnumId {
@@ -167,6 +249,17 @@ impl AstItemDef<ast::EnumDef> for EnumId {
167 } 249 }
168} 250}
169 251
252// FIXME: rename to `VariantId`, only enums can ave variants
253#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
254pub struct EnumVariantId {
255 parent: EnumId,
256 local_id: LocalEnumVariantId,
257}
258
259#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
260pub(crate) struct LocalEnumVariantId(RawId);
261impl_arena_id!(LocalEnumVariantId);
262
170#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 263#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
171pub struct ConstId(salsa::InternId); 264pub struct ConstId(salsa::InternId);
172impl_intern_key!(ConstId); 265impl_intern_key!(ConstId);
diff --git a/crates/ra_hir/src/name.rs b/crates/ra_hir_def/src/name.rs
index 1e0b8c350..720896ee8 100644
--- a/crates/ra_hir/src/name.rs
+++ b/crates/ra_hir_def/src/name.rs
@@ -33,7 +33,7 @@ impl Name {
33 Name(Repr::Text(text)) 33 Name(Repr::Text(text))
34 } 34 }
35 35
36 pub(crate) fn new_tuple_field(idx: usize) -> Name { 36 pub fn new_tuple_field(idx: usize) -> Name {
37 Name(Repr::TupleField(idx)) 37 Name(Repr::TupleField(idx))
38 } 38 }
39 39
@@ -52,11 +52,11 @@ impl Name {
52 } 52 }
53 } 53 }
54 54
55 pub(crate) fn missing() -> Name { 55 pub fn missing() -> Name {
56 Name::new_text("[missing name]".into()) 56 Name::new_text("[missing name]".into())
57 } 57 }
58 58
59 pub(crate) fn as_tuple_index(&self) -> Option<usize> { 59 pub fn as_tuple_index(&self) -> Option<usize> {
60 match self.0 { 60 match self.0 {
61 Repr::TupleField(idx) => Some(idx), 61 Repr::TupleField(idx) => Some(idx),
62 _ => None, 62 _ => None,
@@ -64,7 +64,7 @@ impl Name {
64 } 64 }
65} 65}
66 66
67pub(crate) trait AsName { 67pub trait AsName {
68 fn as_name(&self) -> Name; 68 fn as_name(&self) -> Name;
69} 69}
70 70
@@ -99,44 +99,44 @@ impl AsName for ra_db::Dependency {
99} 99}
100 100
101// Primitives 101// Primitives
102pub(crate) const ISIZE: Name = Name::new_inline_ascii(5, b"isize"); 102pub const ISIZE: Name = Name::new_inline_ascii(5, b"isize");
103pub(crate) const I8: Name = Name::new_inline_ascii(2, b"i8"); 103pub const I8: Name = Name::new_inline_ascii(2, b"i8");
104pub(crate) const I16: Name = Name::new_inline_ascii(3, b"i16"); 104pub const I16: Name = Name::new_inline_ascii(3, b"i16");
105pub(crate) const I32: Name = Name::new_inline_ascii(3, b"i32"); 105pub const I32: Name = Name::new_inline_ascii(3, b"i32");
106pub(crate) const I64: Name = Name::new_inline_ascii(3, b"i64"); 106pub const I64: Name = Name::new_inline_ascii(3, b"i64");
107pub(crate) const I128: Name = Name::new_inline_ascii(4, b"i128"); 107pub const I128: Name = Name::new_inline_ascii(4, b"i128");
108pub(crate) const USIZE: Name = Name::new_inline_ascii(5, b"usize"); 108pub const USIZE: Name = Name::new_inline_ascii(5, b"usize");
109pub(crate) const U8: Name = Name::new_inline_ascii(2, b"u8"); 109pub const U8: Name = Name::new_inline_ascii(2, b"u8");
110pub(crate) const U16: Name = Name::new_inline_ascii(3, b"u16"); 110pub const U16: Name = Name::new_inline_ascii(3, b"u16");
111pub(crate) const U32: Name = Name::new_inline_ascii(3, b"u32"); 111pub const U32: Name = Name::new_inline_ascii(3, b"u32");
112pub(crate) const U64: Name = Name::new_inline_ascii(3, b"u64"); 112pub const U64: Name = Name::new_inline_ascii(3, b"u64");
113pub(crate) const U128: Name = Name::new_inline_ascii(4, b"u128"); 113pub const U128: Name = Name::new_inline_ascii(4, b"u128");
114pub(crate) const F32: Name = Name::new_inline_ascii(3, b"f32"); 114pub const F32: Name = Name::new_inline_ascii(3, b"f32");
115pub(crate) const F64: Name = Name::new_inline_ascii(3, b"f64"); 115pub const F64: Name = Name::new_inline_ascii(3, b"f64");
116pub(crate) const BOOL: Name = Name::new_inline_ascii(4, b"bool"); 116pub const BOOL: Name = Name::new_inline_ascii(4, b"bool");
117pub(crate) const CHAR: Name = Name::new_inline_ascii(4, b"char"); 117pub const CHAR: Name = Name::new_inline_ascii(4, b"char");
118pub(crate) const STR: Name = Name::new_inline_ascii(3, b"str"); 118pub const STR: Name = Name::new_inline_ascii(3, b"str");
119 119
120// Special names 120// Special names
121pub(crate) const SELF_PARAM: Name = Name::new_inline_ascii(4, b"self"); 121pub const SELF_PARAM: Name = Name::new_inline_ascii(4, b"self");
122pub(crate) const SELF_TYPE: Name = Name::new_inline_ascii(4, b"Self"); 122pub const SELF_TYPE: Name = Name::new_inline_ascii(4, b"Self");
123pub(crate) const MACRO_RULES: Name = Name::new_inline_ascii(11, b"macro_rules"); 123pub const MACRO_RULES: Name = Name::new_inline_ascii(11, b"macro_rules");
124 124
125// Components of known path (value or mod name) 125// Components of known path (value or mod name)
126pub(crate) const STD: Name = Name::new_inline_ascii(3, b"std"); 126pub const STD: Name = Name::new_inline_ascii(3, b"std");
127pub(crate) const ITER: Name = Name::new_inline_ascii(4, b"iter"); 127pub const ITER: Name = Name::new_inline_ascii(4, b"iter");
128pub(crate) const OPS: Name = Name::new_inline_ascii(3, b"ops"); 128pub const OPS: Name = Name::new_inline_ascii(3, b"ops");
129pub(crate) const FUTURE: Name = Name::new_inline_ascii(6, b"future"); 129pub const FUTURE: Name = Name::new_inline_ascii(6, b"future");
130pub(crate) const RESULT: Name = Name::new_inline_ascii(6, b"result"); 130pub const RESULT: Name = Name::new_inline_ascii(6, b"result");
131pub(crate) const BOXED: Name = Name::new_inline_ascii(5, b"boxed"); 131pub const BOXED: Name = Name::new_inline_ascii(5, b"boxed");
132 132
133// Components of known path (type name) 133// Components of known path (type name)
134pub(crate) const INTO_ITERATOR_TYPE: Name = Name::new_inline_ascii(12, b"IntoIterator"); 134pub const INTO_ITERATOR_TYPE: Name = Name::new_inline_ascii(12, b"IntoIterator");
135pub(crate) const ITEM_TYPE: Name = Name::new_inline_ascii(4, b"Item"); 135pub const ITEM_TYPE: Name = Name::new_inline_ascii(4, b"Item");
136pub(crate) const TRY_TYPE: Name = Name::new_inline_ascii(3, b"Try"); 136pub const TRY_TYPE: Name = Name::new_inline_ascii(3, b"Try");
137pub(crate) const OK_TYPE: Name = Name::new_inline_ascii(2, b"Ok"); 137pub const OK_TYPE: Name = Name::new_inline_ascii(2, b"Ok");
138pub(crate) const FUTURE_TYPE: Name = Name::new_inline_ascii(6, b"Future"); 138pub const FUTURE_TYPE: Name = Name::new_inline_ascii(6, b"Future");
139pub(crate) const RESULT_TYPE: Name = Name::new_inline_ascii(6, b"Result"); 139pub const RESULT_TYPE: Name = Name::new_inline_ascii(6, b"Result");
140pub(crate) const OUTPUT_TYPE: Name = Name::new_inline_ascii(6, b"Output"); 140pub const OUTPUT_TYPE: Name = Name::new_inline_ascii(6, b"Output");
141pub(crate) const TARGET_TYPE: Name = Name::new_inline_ascii(6, b"Target"); 141pub const TARGET_TYPE: Name = Name::new_inline_ascii(6, b"Target");
142pub(crate) const BOX_TYPE: Name = Name::new_inline_ascii(3, b"Box"); 142pub const BOX_TYPE: Name = Name::new_inline_ascii(3, b"Box");
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
new file mode 100644
index 000000000..5893708e8
--- /dev/null
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -0,0 +1,3 @@
1//! FIXME: write short doc here
2
3pub mod raw;
diff --git a/crates/ra_hir/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs
index 57f2929c3..86b4fef96 100644
--- a/crates/ra_hir/src/nameres/raw.rs
+++ b/crates/ra_hir_def/src/nameres/raw.rs
@@ -2,17 +2,20 @@
2 2
3use std::{ops::Index, sync::Arc}; 3use std::{ops::Index, sync::Arc};
4 4
5use hir_expand::{ast_id_map::AstIdMap, db::AstDatabase};
5use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; 6use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId};
6use ra_syntax::{ 7use ra_syntax::{
7 ast::{self, AttrsOwner, NameOwner}, 8 ast::{self, AttrsOwner, NameOwner},
8 AstNode, AstPtr, SourceFile, 9 AstNode, AstPtr, SourceFile,
9}; 10};
10use test_utils::tested_by;
11 11
12use crate::{ 12use crate::{
13 attr::Attr, 13 attr::Attr,
14 db::{AstDatabase, DefDatabase}, 14 db::DefDatabase2,
15 AsName, AstIdMap, Either, FileAstId, HirFileId, ModuleSource, Name, Path, Source, 15 either::Either,
16 name::{AsName, Name},
17 path::Path,
18 FileAstId, HirFileId, ModuleSource, Source,
16}; 19};
17 20
18/// `RawItems` is a set of top-level items in a file (except for impls). 21/// `RawItems` is a set of top-level items in a file (except for impls).
@@ -48,7 +51,7 @@ impl ImportSourceMap {
48 self.map.insert(import, ptr) 51 self.map.insert(import, ptr)
49 } 52 }
50 53
51 pub(crate) fn get(&self, source: &ModuleSource, import: ImportId) -> ImportSource { 54 pub fn get(&self, source: &ModuleSource, import: ImportId) -> ImportSource {
52 let file = match source { 55 let file = match source {
53 ModuleSource::SourceFile(file) => file.clone(), 56 ModuleSource::SourceFile(file) => file.clone(),
54 ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(), 57 ModuleSource::Module(m) => m.syntax().ancestors().find_map(SourceFile::cast).unwrap(),
@@ -60,14 +63,14 @@ impl ImportSourceMap {
60 63
61impl RawItems { 64impl RawItems {
62 pub(crate) fn raw_items_query( 65 pub(crate) fn raw_items_query(
63 db: &(impl DefDatabase + AstDatabase), 66 db: &(impl DefDatabase2 + AstDatabase),
64 file_id: HirFileId, 67 file_id: HirFileId,
65 ) -> Arc<RawItems> { 68 ) -> Arc<RawItems> {
66 db.raw_items_with_source_map(file_id).0 69 db.raw_items_with_source_map(file_id).0
67 } 70 }
68 71
69 pub(crate) fn raw_items_with_source_map_query( 72 pub(crate) fn raw_items_with_source_map_query(
70 db: &(impl DefDatabase + AstDatabase), 73 db: &(impl DefDatabase2 + AstDatabase),
71 file_id: HirFileId, 74 file_id: HirFileId,
72 ) -> (Arc<RawItems>, Arc<ImportSourceMap>) { 75 ) -> (Arc<RawItems>, Arc<ImportSourceMap>) {
73 let mut collector = RawItemsCollector { 76 let mut collector = RawItemsCollector {
@@ -87,7 +90,7 @@ impl RawItems {
87 (Arc::new(collector.raw_items), Arc::new(collector.source_map)) 90 (Arc::new(collector.raw_items), Arc::new(collector.source_map))
88 } 91 }
89 92
90 pub(super) fn items(&self) -> &[RawItem] { 93 pub fn items(&self) -> &[RawItem] {
91 &self.items 94 &self.items
92 } 95 }
93} 96}
@@ -124,19 +127,19 @@ impl Index<Macro> for RawItems {
124type Attrs = Option<Arc<[Attr]>>; 127type Attrs = Option<Arc<[Attr]>>;
125 128
126#[derive(Debug, PartialEq, Eq, Clone)] 129#[derive(Debug, PartialEq, Eq, Clone)]
127pub(super) struct RawItem { 130pub struct RawItem {
128 attrs: Attrs, 131 attrs: Attrs,
129 pub(super) kind: RawItemKind, 132 pub kind: RawItemKind,
130} 133}
131 134
132impl RawItem { 135impl RawItem {
133 pub(super) fn attrs(&self) -> &[Attr] { 136 pub fn attrs(&self) -> &[Attr] {
134 self.attrs.as_ref().map_or(&[], |it| &*it) 137 self.attrs.as_ref().map_or(&[], |it| &*it)
135 } 138 }
136} 139}
137 140
138#[derive(Debug, PartialEq, Eq, Clone, Copy)] 141#[derive(Debug, PartialEq, Eq, Clone, Copy)]
139pub(super) enum RawItemKind { 142pub enum RawItemKind {
140 Module(Module), 143 Module(Module),
141 Import(ImportId), 144 Import(ImportId),
142 Def(Def), 145 Def(Def),
@@ -144,11 +147,11 @@ pub(super) enum RawItemKind {
144} 147}
145 148
146#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 149#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
147pub(super) struct Module(RawId); 150pub struct Module(RawId);
148impl_arena_id!(Module); 151impl_arena_id!(Module);
149 152
150#[derive(Debug, PartialEq, Eq)] 153#[derive(Debug, PartialEq, Eq)]
151pub(super) enum ModuleData { 154pub enum ModuleData {
152 Declaration { name: Name, ast_id: FileAstId<ast::Module> }, 155 Declaration { name: Name, ast_id: FileAstId<ast::Module> },
153 Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> }, 156 Definition { name: Name, ast_id: FileAstId<ast::Module>, items: Vec<RawItem> },
154} 157}
@@ -159,26 +162,26 @@ impl_arena_id!(ImportId);
159 162
160#[derive(Debug, Clone, PartialEq, Eq)] 163#[derive(Debug, Clone, PartialEq, Eq)]
161pub struct ImportData { 164pub struct ImportData {
162 pub(super) path: Path, 165 pub path: Path,
163 pub(super) alias: Option<Name>, 166 pub alias: Option<Name>,
164 pub(super) is_glob: bool, 167 pub is_glob: bool,
165 pub(super) is_prelude: bool, 168 pub is_prelude: bool,
166 pub(super) is_extern_crate: bool, 169 pub is_extern_crate: bool,
167 pub(super) is_macro_use: bool, 170 pub is_macro_use: bool,
168} 171}
169 172
170#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 173#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
171pub(super) struct Def(RawId); 174pub struct Def(RawId);
172impl_arena_id!(Def); 175impl_arena_id!(Def);
173 176
174#[derive(Debug, PartialEq, Eq)] 177#[derive(Debug, PartialEq, Eq)]
175pub(super) struct DefData { 178pub struct DefData {
176 pub(super) name: Name, 179 pub name: Name,
177 pub(super) kind: DefKind, 180 pub kind: DefKind,
178} 181}
179 182
180#[derive(Debug, PartialEq, Eq, Clone, Copy)] 183#[derive(Debug, PartialEq, Eq, Clone, Copy)]
181pub(super) enum DefKind { 184pub enum DefKind {
182 Function(FileAstId<ast::FnDef>), 185 Function(FileAstId<ast::FnDef>),
183 Struct(FileAstId<ast::StructDef>), 186 Struct(FileAstId<ast::StructDef>),
184 Union(FileAstId<ast::StructDef>), 187 Union(FileAstId<ast::StructDef>),
@@ -190,15 +193,15 @@ pub(super) enum DefKind {
190} 193}
191 194
192#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 195#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
193pub(super) struct Macro(RawId); 196pub struct Macro(RawId);
194impl_arena_id!(Macro); 197impl_arena_id!(Macro);
195 198
196#[derive(Debug, PartialEq, Eq)] 199#[derive(Debug, PartialEq, Eq)]
197pub(super) struct MacroData { 200pub struct MacroData {
198 pub(super) ast_id: FileAstId<ast::MacroCall>, 201 pub ast_id: FileAstId<ast::MacroCall>,
199 pub(super) path: Path, 202 pub path: Path,
200 pub(super) name: Option<Name>, 203 pub name: Option<Name>,
201 pub(super) export: bool, 204 pub export: bool,
202} 205}
203 206
204struct RawItemsCollector<DB> { 207struct RawItemsCollector<DB> {
@@ -297,7 +300,8 @@ impl<DB: AstDatabase> RawItemsCollector<&DB> {
297 self.push_item(current_module, attrs, RawItemKind::Module(item)); 300 self.push_item(current_module, attrs, RawItemKind::Module(item));
298 return; 301 return;
299 } 302 }
300 tested_by!(name_res_works_for_broken_modules); 303 // FIXME: restore this mark once we complete hir splitting
304 // tested_by!(name_res_works_for_broken_modules);
301 } 305 }
302 306
303 fn add_use_item(&mut self, current_module: Option<Module>, use_item: ast::UseItem) { 307 fn add_use_item(&mut self, current_module: Option<Module>, use_item: ast::UseItem) {
diff --git a/crates/ra_hir/src/path.rs b/crates/ra_hir_def/src/path.rs
index bbe536bcb..fe060437d 100644
--- a/crates/ra_hir/src/path.rs
+++ b/crates/ra_hir_def/src/path.rs
@@ -2,12 +2,18 @@
2 2
3use std::{iter, sync::Arc}; 3use std::{iter, sync::Arc};
4 4
5use hir_expand::db::AstDatabase;
6use ra_db::CrateId;
5use ra_syntax::{ 7use ra_syntax::{
6 ast::{self, NameOwner, TypeAscriptionOwner}, 8 ast::{self, NameOwner, TypeAscriptionOwner},
7 AstNode, 9 AstNode,
8}; 10};
9 11
10use crate::{db::AstDatabase, name, type_ref::TypeRef, AsName, Crate, Name, Source}; 12use crate::{
13 name::{self, AsName, Name},
14 type_ref::TypeRef,
15 Source,
16};
11 17
12#[derive(Debug, Clone, PartialEq, Eq, Hash)] 18#[derive(Debug, Clone, PartialEq, Eq, Hash)]
13pub struct Path { 19pub struct Path {
@@ -55,7 +61,7 @@ pub enum PathKind {
55 // Type based path like `<T>::foo` 61 // Type based path like `<T>::foo`
56 Type(Box<TypeRef>), 62 Type(Box<TypeRef>),
57 // `$crate` from macro expansion 63 // `$crate` from macro expansion
58 DollarCrate(Crate), 64 DollarCrate(CrateId),
59} 65}
60 66
61impl Path { 67impl Path {
@@ -66,12 +72,7 @@ impl Path {
66 mut cb: impl FnMut(Path, &ast::UseTree, bool, Option<Name>), 72 mut cb: impl FnMut(Path, &ast::UseTree, bool, Option<Name>),
67 ) { 73 ) {
68 if let Some(tree) = item_src.ast.use_tree() { 74 if let Some(tree) = item_src.ast.use_tree() {
69 expand_use_tree( 75 expand_use_tree(None, tree, &|| item_src.file_id.macro_crate(db), &mut cb);
70 None,
71 tree,
72 &|| item_src.file_id.macro_crate(db).map(|crate_id| Crate { crate_id }),
73 &mut cb,
74 );
75 } 76 }
76 } 77 }
77 78
@@ -95,10 +96,10 @@ impl Path {
95 /// It correctly handles `$crate` based path from macro call. 96 /// It correctly handles `$crate` based path from macro call.
96 pub fn from_src(source: Source<ast::Path>, db: &impl AstDatabase) -> Option<Path> { 97 pub fn from_src(source: Source<ast::Path>, db: &impl AstDatabase) -> Option<Path> {
97 let file_id = source.file_id; 98 let file_id = source.file_id;
98 Path::parse(source.ast, &|| file_id.macro_crate(db).map(|crate_id| Crate { crate_id })) 99 Path::parse(source.ast, &|| file_id.macro_crate(db))
99 } 100 }
100 101
101 fn parse(mut path: ast::Path, macro_crate: &impl Fn() -> Option<Crate>) -> Option<Path> { 102 fn parse(mut path: ast::Path, macro_crate: &impl Fn() -> Option<CrateId>) -> Option<Path> {
102 let mut kind = PathKind::Plain; 103 let mut kind = PathKind::Plain;
103 let mut segments = Vec::new(); 104 let mut segments = Vec::new();
104 loop { 105 loop {
@@ -229,7 +230,7 @@ impl Path {
229} 230}
230 231
231impl GenericArgs { 232impl GenericArgs {
232 pub(crate) fn from_ast(node: ast::TypeArgList) -> Option<GenericArgs> { 233 pub fn from_ast(node: ast::TypeArgList) -> Option<GenericArgs> {
233 let mut args = Vec::new(); 234 let mut args = Vec::new();
234 for type_arg in node.type_args() { 235 for type_arg in node.type_args() {
235 let type_ref = TypeRef::from_ast_opt(type_arg.type_ref()); 236 let type_ref = TypeRef::from_ast_opt(type_arg.type_ref());
@@ -293,7 +294,7 @@ impl From<Name> for Path {
293fn expand_use_tree( 294fn expand_use_tree(
294 prefix: Option<Path>, 295 prefix: Option<Path>,
295 tree: ast::UseTree, 296 tree: ast::UseTree,
296 macro_crate: &impl Fn() -> Option<Crate>, 297 macro_crate: &impl Fn() -> Option<CrateId>,
297 cb: &mut impl FnMut(Path, &ast::UseTree, bool, Option<Name>), 298 cb: &mut impl FnMut(Path, &ast::UseTree, bool, Option<Name>),
298) { 299) {
299 if let Some(use_tree_list) = tree.use_tree_list() { 300 if let Some(use_tree_list) = tree.use_tree_list() {
@@ -338,7 +339,7 @@ fn expand_use_tree(
338fn convert_path( 339fn convert_path(
339 prefix: Option<Path>, 340 prefix: Option<Path>,
340 path: ast::Path, 341 path: ast::Path,
341 macro_crate: &impl Fn() -> Option<Crate>, 342 macro_crate: &impl Fn() -> Option<CrateId>,
342) -> Option<Path> { 343) -> Option<Path> {
343 let prefix = if let Some(qual) = path.qualifier() { 344 let prefix = if let Some(qual) = path.qualifier() {
344 Some(convert_path(prefix, qual, macro_crate)?) 345 Some(convert_path(prefix, qual, macro_crate)?)
diff --git a/crates/ra_hir/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs
index 2cf06b250..8af061116 100644
--- a/crates/ra_hir/src/type_ref.rs
+++ b/crates/ra_hir_def/src/type_ref.rs
@@ -3,7 +3,7 @@
3 3
4use ra_syntax::ast::{self, TypeAscriptionOwner, TypeBoundsOwner}; 4use ra_syntax::ast::{self, TypeAscriptionOwner, TypeBoundsOwner};
5 5
6use crate::Path; 6use crate::path::Path;
7 7
8#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] 8#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
9pub enum Mutability { 9pub enum Mutability {
@@ -64,7 +64,7 @@ pub enum TypeBound {
64 64
65impl TypeRef { 65impl TypeRef {
66 /// Converts an `ast::TypeRef` to a `hir::TypeRef`. 66 /// Converts an `ast::TypeRef` to a `hir::TypeRef`.
67 pub(crate) fn from_ast(node: ast::TypeRef) -> Self { 67 pub fn from_ast(node: ast::TypeRef) -> Self {
68 match node { 68 match node {
69 ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()), 69 ast::TypeRef::ParenType(inner) => TypeRef::from_ast_opt(inner.type_ref()),
70 ast::TypeRef::TupleType(inner) => { 70 ast::TypeRef::TupleType(inner) => {
@@ -113,7 +113,7 @@ impl TypeRef {
113 } 113 }
114 } 114 }
115 115
116 pub(crate) fn from_ast_opt(node: Option<ast::TypeRef>) -> Self { 116 pub fn from_ast_opt(node: Option<ast::TypeRef>) -> Self {
117 if let Some(node) = node { 117 if let Some(node) = node {
118 TypeRef::from_ast(node) 118 TypeRef::from_ast(node)
119 } else { 119 } else {
@@ -135,7 +135,7 @@ pub(crate) fn type_bounds_from_ast(type_bounds_opt: Option<ast::TypeBoundList>)
135} 135}
136 136
137impl TypeBound { 137impl TypeBound {
138 pub(crate) fn from_ast(node: ast::TypeBound) -> Self { 138 pub fn from_ast(node: ast::TypeBound) -> Self {
139 match node.kind() { 139 match node.kind() {
140 ast::TypeBoundKind::PathType(path_type) => { 140 ast::TypeBoundKind::PathType(path_type) => {
141 let path = match path_type.path() { 141 let path = match path_type.path() {
diff --git a/crates/ra_hir_expand/src/lib.rs b/crates/ra_hir_expand/src/lib.rs
index 6b3538673..3c0ef8f1c 100644
--- a/crates/ra_hir_expand/src/lib.rs
+++ b/crates/ra_hir_expand/src/lib.rs
@@ -12,7 +12,7 @@ use std::hash::{Hash, Hasher};
12use ra_db::{salsa, CrateId, FileId}; 12use ra_db::{salsa, CrateId, FileId};
13use ra_syntax::ast::{self, AstNode}; 13use ra_syntax::ast::{self, AstNode};
14 14
15use crate::{ast_id_map::FileAstId, db::AstDatabase}; 15use crate::ast_id_map::FileAstId;
16 16
17/// Input to the analyzer is a set of files, where each file is identified by 17/// Input to the analyzer is a set of files, where each file is identified by
18/// `FileId` and contains source code. However, another source of source code in 18/// `FileId` and contains source code. However, another source of source code in
@@ -50,7 +50,7 @@ impl From<MacroFile> for HirFileId {
50impl HirFileId { 50impl HirFileId {
51 /// For macro-expansion files, returns the file original source file the 51 /// For macro-expansion files, returns the file original source file the
52 /// expansion originated from. 52 /// expansion originated from.
53 pub fn original_file(self, db: &dyn AstDatabase) -> FileId { 53 pub fn original_file(self, db: &dyn db::AstDatabase) -> FileId {
54 match self.0 { 54 match self.0 {
55 HirFileIdRepr::FileId(file_id) => file_id, 55 HirFileIdRepr::FileId(file_id) => file_id,
56 HirFileIdRepr::MacroFile(macro_file) => { 56 HirFileIdRepr::MacroFile(macro_file) => {
@@ -61,7 +61,7 @@ impl HirFileId {
61 } 61 }
62 62
63 /// Get the crate which the macro lives in, if it is a macro file. 63 /// Get the crate which the macro lives in, if it is a macro file.
64 pub fn macro_crate(self, db: &dyn AstDatabase) -> Option<CrateId> { 64 pub fn macro_crate(self, db: &dyn db::AstDatabase) -> Option<CrateId> {
65 match self.0 { 65 match self.0 {
66 HirFileIdRepr::FileId(_) => None, 66 HirFileIdRepr::FileId(_) => None,
67 HirFileIdRepr::MacroFile(macro_file) => { 67 HirFileIdRepr::MacroFile(macro_file) => {
@@ -154,7 +154,7 @@ impl<N: AstNode> AstId<N> {
154 self.file_id 154 self.file_id
155 } 155 }
156 156
157 pub fn to_node(&self, db: &dyn AstDatabase) -> N { 157 pub fn to_node(&self, db: &dyn db::AstDatabase) -> N {
158 let root = db.parse_or_expand(self.file_id).unwrap(); 158 let root = db.parse_or_expand(self.file_id).unwrap();
159 db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root) 159 db.ast_id_map(self.file_id).get(self.file_ast_id).to_node(&root)
160 } 160 }
diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs
index 9146b647a..785e71808 100644
--- a/crates/ra_ide_api/src/db.rs
+++ b/crates/ra_ide_api/src/db.rs
@@ -23,6 +23,7 @@ use crate::{
23 hir::db::InternDatabaseStorage, 23 hir::db::InternDatabaseStorage,
24 hir::db::AstDatabaseStorage, 24 hir::db::AstDatabaseStorage,
25 hir::db::DefDatabaseStorage, 25 hir::db::DefDatabaseStorage,
26 hir::db::DefDatabase2Storage,
26 hir::db::HirDatabaseStorage 27 hir::db::HirDatabaseStorage
27)] 28)]
28#[derive(Debug)] 29#[derive(Debug)]