aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-03-13 15:05:46 +0000
committerAleksey Kladov <[email protected]>2020-03-16 16:42:30 +0000
commit9faea2364dee4fbc9391ad233c570b70256ef002 (patch)
tree160af959553ce57fdfcbc0a6c79bafcc3611aeea /crates/ra_hir_def
parent648df02953a6ebf87a5876668eceba208687e8a7 (diff)
Use `dyn Trait` for working with databse
It improves compile time in `--release` mode quite a bit, it doesn't really slow things down and, conceptually, it seems closer to what we want the physical architecture to look like (we don't want to monomorphise EVERYTHING in a single leaf crate).
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r--crates/ra_hir_def/src/adt.rs16
-rw-r--r--crates/ra_hir_def/src/attr.rs14
-rw-r--r--crates/ra_hir_def/src/body.rs22
-rw-r--r--crates/ra_hir_def/src/body/lower.rs11
-rw-r--r--crates/ra_hir_def/src/body/scope.rs2
-rw-r--r--crates/ra_hir_def/src/child_by_source.rs20
-rw-r--r--crates/ra_hir_def/src/data.rs18
-rw-r--r--crates/ra_hir_def/src/db.rs10
-rw-r--r--crates/ra_hir_def/src/docs.rs4
-rw-r--r--crates/ra_hir_def/src/find_path.rs8
-rw-r--r--crates/ra_hir_def/src/generics.rs8
-rw-r--r--crates/ra_hir_def/src/lang_item.rs10
-rw-r--r--crates/ra_hir_def/src/lib.rs48
-rw-r--r--crates/ra_hir_def/src/nameres.rs25
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs22
-rw-r--r--crates/ra_hir_def/src/nameres/mod_resolution.rs4
-rw-r--r--crates/ra_hir_def/src/nameres/path_resolution.rs8
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs8
-rw-r--r--crates/ra_hir_def/src/resolver.rs62
-rw-r--r--crates/ra_hir_def/src/src.rs12
-rw-r--r--crates/ra_hir_def/src/test_db.rs18
-rw-r--r--crates/ra_hir_def/src/visibility.rs12
22 files changed, 185 insertions, 177 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs
index 2bdfc2b8d..d55c49938 100644
--- a/crates/ra_hir_def/src/adt.rs
+++ b/crates/ra_hir_def/src/adt.rs
@@ -52,14 +52,14 @@ pub struct StructFieldData {
52} 52}
53 53
54impl StructData { 54impl StructData {
55 pub(crate) fn struct_data_query(db: &impl DefDatabase, id: StructId) -> Arc<StructData> { 55 pub(crate) fn struct_data_query(db: &dyn DefDatabase, id: StructId) -> Arc<StructData> {
56 let src = id.lookup(db).source(db); 56 let src = id.lookup(db).source(db);
57 let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); 57 let name = src.value.name().map_or_else(Name::missing, |n| n.as_name());
58 let variant_data = VariantData::new(db, src.map(|s| s.kind())); 58 let variant_data = VariantData::new(db, src.map(|s| s.kind()));
59 let variant_data = Arc::new(variant_data); 59 let variant_data = Arc::new(variant_data);
60 Arc::new(StructData { name, variant_data }) 60 Arc::new(StructData { name, variant_data })
61 } 61 }
62 pub(crate) fn union_data_query(db: &impl DefDatabase, id: UnionId) -> Arc<StructData> { 62 pub(crate) fn union_data_query(db: &dyn DefDatabase, id: UnionId) -> Arc<StructData> {
63 let src = id.lookup(db).source(db); 63 let src = id.lookup(db).source(db);
64 let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); 64 let name = src.value.name().map_or_else(Name::missing, |n| n.as_name());
65 let variant_data = VariantData::new( 65 let variant_data = VariantData::new(
@@ -76,7 +76,7 @@ impl StructData {
76} 76}
77 77
78impl EnumData { 78impl EnumData {
79 pub(crate) fn enum_data_query(db: &impl DefDatabase, e: EnumId) -> Arc<EnumData> { 79 pub(crate) fn enum_data_query(db: &dyn DefDatabase, e: EnumId) -> Arc<EnumData> {
80 let _p = profile("enum_data_query"); 80 let _p = profile("enum_data_query");
81 let src = e.lookup(db).source(db); 81 let src = e.lookup(db).source(db);
82 let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); 82 let name = src.value.name().map_or_else(Name::missing, |n| n.as_name());
@@ -94,7 +94,7 @@ impl EnumData {
94impl HasChildSource for EnumId { 94impl HasChildSource for EnumId {
95 type ChildId = LocalEnumVariantId; 95 type ChildId = LocalEnumVariantId;
96 type Value = ast::EnumVariant; 96 type Value = ast::EnumVariant;
97 fn child_source(&self, db: &impl DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> { 97 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> {
98 let src = self.lookup(db).source(db); 98 let src = self.lookup(db).source(db);
99 let mut trace = Trace::new_for_map(); 99 let mut trace = Trace::new_for_map();
100 lower_enum(db, &mut trace, &src); 100 lower_enum(db, &mut trace, &src);
@@ -103,7 +103,7 @@ impl HasChildSource for EnumId {
103} 103}
104 104
105fn lower_enum( 105fn lower_enum(
106 db: &impl DefDatabase, 106 db: &dyn DefDatabase,
107 trace: &mut Trace<LocalEnumVariantId, EnumVariantData, ast::EnumVariant>, 107 trace: &mut Trace<LocalEnumVariantId, EnumVariantData, ast::EnumVariant>,
108 ast: &InFile<ast::EnumDef>, 108 ast: &InFile<ast::EnumDef>,
109) { 109) {
@@ -119,7 +119,7 @@ fn lower_enum(
119} 119}
120 120
121impl VariantData { 121impl VariantData {
122 fn new(db: &impl DefDatabase, flavor: InFile<ast::StructKind>) -> Self { 122 fn new(db: &dyn DefDatabase, flavor: InFile<ast::StructKind>) -> Self {
123 let mut trace = Trace::new_for_arena(); 123 let mut trace = Trace::new_for_arena();
124 match lower_struct(db, &mut trace, &flavor) { 124 match lower_struct(db, &mut trace, &flavor) {
125 StructKind::Tuple => VariantData::Tuple(trace.into_arena()), 125 StructKind::Tuple => VariantData::Tuple(trace.into_arena()),
@@ -153,7 +153,7 @@ impl HasChildSource for VariantId {
153 type ChildId = LocalStructFieldId; 153 type ChildId = LocalStructFieldId;
154 type Value = Either<ast::TupleFieldDef, ast::RecordFieldDef>; 154 type Value = Either<ast::TupleFieldDef, ast::RecordFieldDef>;
155 155
156 fn child_source(&self, db: &impl DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> { 156 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> {
157 let src = match self { 157 let src = match self {
158 VariantId::EnumVariantId(it) => { 158 VariantId::EnumVariantId(it) => {
159 // I don't really like the fact that we call into parent source 159 // I don't really like the fact that we call into parent source
@@ -182,7 +182,7 @@ pub enum StructKind {
182} 182}
183 183
184fn lower_struct( 184fn lower_struct(
185 db: &impl DefDatabase, 185 db: &dyn DefDatabase,
186 trace: &mut Trace< 186 trace: &mut Trace<
187 LocalStructFieldId, 187 LocalStructFieldId,
188 StructFieldData, 188 StructFieldData,
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs
index 9efa4970c..71a18f5e1 100644
--- a/crates/ra_hir_def/src/attr.rs
+++ b/crates/ra_hir_def/src/attr.rs
@@ -32,7 +32,7 @@ impl ops::Deref for Attrs {
32} 32}
33 33
34impl Attrs { 34impl Attrs {
35 pub(crate) fn attrs_query(db: &impl DefDatabase, def: AttrDefId) -> Attrs { 35 pub(crate) fn attrs_query(db: &dyn DefDatabase, def: AttrDefId) -> Attrs {
36 match def { 36 match def {
37 AttrDefId::ModuleId(module) => { 37 AttrDefId::ModuleId(module) => {
38 let def_map = db.crate_def_map(module.krate); 38 let def_map = db.crate_def_map(module.krate);
@@ -71,8 +71,8 @@ impl Attrs {
71 } 71 }
72 } 72 }
73 73
74 fn from_attrs_owner(db: &impl DefDatabase, owner: InFile<&dyn AttrsOwner>) -> Attrs { 74 fn from_attrs_owner(db: &dyn DefDatabase, owner: InFile<&dyn AttrsOwner>) -> Attrs {
75 let hygiene = Hygiene::new(db, owner.file_id); 75 let hygiene = Hygiene::new(db.upcast(), owner.file_id);
76 Attrs::new(owner.value, &hygiene) 76 Attrs::new(owner.value, &hygiene)
77 } 77 }
78 78
@@ -155,20 +155,18 @@ impl<'a> AttrQuery<'a> {
155 } 155 }
156} 156}
157 157
158fn attrs_from_ast<D, N>(src: AstId<N>, db: &D) -> Attrs 158fn attrs_from_ast<N>(src: AstId<N>, db: &dyn DefDatabase) -> Attrs
159where 159where
160 N: ast::AttrsOwner, 160 N: ast::AttrsOwner,
161 D: DefDatabase,
162{ 161{
163 let src = InFile::new(src.file_id, src.to_node(db)); 162 let src = InFile::new(src.file_id, src.to_node(db.upcast()));
164 Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner)) 163 Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner))
165} 164}
166 165
167fn attrs_from_loc<T, D>(node: T, db: &D) -> Attrs 166fn attrs_from_loc<T>(node: T, db: &dyn DefDatabase) -> Attrs
168where 167where
169 T: HasSource, 168 T: HasSource,
170 T::Value: ast::AttrsOwner, 169 T::Value: ast::AttrsOwner,
171 D: DefDatabase,
172{ 170{
173 let src = node.source(db); 171 let src = node.source(db);
174 Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner)) 172 Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner))
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index 2bc405a59..34561ee73 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -34,19 +34,19 @@ pub(crate) struct Expander {
34 34
35impl Expander { 35impl Expander {
36 pub(crate) fn new( 36 pub(crate) fn new(
37 db: &impl DefDatabase, 37 db: &dyn DefDatabase,
38 current_file_id: HirFileId, 38 current_file_id: HirFileId,
39 module: ModuleId, 39 module: ModuleId,
40 ) -> Expander { 40 ) -> Expander {
41 let crate_def_map = db.crate_def_map(module.krate); 41 let crate_def_map = db.crate_def_map(module.krate);
42 let hygiene = Hygiene::new(db, current_file_id); 42 let hygiene = Hygiene::new(db.upcast(), current_file_id);
43 let ast_id_map = db.ast_id_map(current_file_id); 43 let ast_id_map = db.ast_id_map(current_file_id);
44 Expander { crate_def_map, current_file_id, hygiene, ast_id_map, module } 44 Expander { crate_def_map, current_file_id, hygiene, ast_id_map, module }
45 } 45 }
46 46
47 pub(crate) fn enter_expand<T: ast::AstNode, DB: DefDatabase>( 47 pub(crate) fn enter_expand<T: ast::AstNode>(
48 &mut self, 48 &mut self,
49 db: &DB, 49 db: &dyn DefDatabase,
50 local_scope: Option<&ItemScope>, 50 local_scope: Option<&ItemScope>,
51 macro_call: ast::MacroCall, 51 macro_call: ast::MacroCall,
52 ) -> Option<(Mark, T)> { 52 ) -> Option<(Mark, T)> {
@@ -70,7 +70,7 @@ impl Expander {
70 ast_id_map: mem::take(&mut self.ast_id_map), 70 ast_id_map: mem::take(&mut self.ast_id_map),
71 bomb: DropBomb::new("expansion mark dropped"), 71 bomb: DropBomb::new("expansion mark dropped"),
72 }; 72 };
73 self.hygiene = Hygiene::new(db, file_id); 73 self.hygiene = Hygiene::new(db.upcast(), file_id);
74 self.current_file_id = file_id; 74 self.current_file_id = file_id;
75 self.ast_id_map = db.ast_id_map(file_id); 75 self.ast_id_map = db.ast_id_map(file_id);
76 76
@@ -84,8 +84,8 @@ impl Expander {
84 None 84 None
85 } 85 }
86 86
87 pub(crate) fn exit(&mut self, db: &impl DefDatabase, mut mark: Mark) { 87 pub(crate) fn exit(&mut self, db: &dyn DefDatabase, mut mark: Mark) {
88 self.hygiene = Hygiene::new(db, mark.file_id); 88 self.hygiene = Hygiene::new(db.upcast(), mark.file_id);
89 self.current_file_id = mark.file_id; 89 self.current_file_id = mark.file_id;
90 self.ast_id_map = mem::take(&mut mark.ast_id_map); 90 self.ast_id_map = mem::take(&mut mark.ast_id_map);
91 mark.bomb.defuse(); 91 mark.bomb.defuse();
@@ -99,7 +99,7 @@ impl Expander {
99 Path::from_src(path, &self.hygiene) 99 Path::from_src(path, &self.hygiene)
100 } 100 }
101 101
102 fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &ModPath) -> Option<MacroDefId> { 102 fn resolve_path_as_macro(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<MacroDefId> {
103 self.crate_def_map 103 self.crate_def_map
104 .resolve_path(db, self.module.local_id, path, BuiltinShadowMode::Other) 104 .resolve_path(db, self.module.local_id, path, BuiltinShadowMode::Other)
105 .0 105 .0
@@ -167,7 +167,7 @@ pub struct SyntheticSyntax;
167 167
168impl Body { 168impl Body {
169 pub(crate) fn body_with_source_map_query( 169 pub(crate) fn body_with_source_map_query(
170 db: &impl DefDatabase, 170 db: &dyn DefDatabase,
171 def: DefWithBodyId, 171 def: DefWithBodyId,
172 ) -> (Arc<Body>, Arc<BodySourceMap>) { 172 ) -> (Arc<Body>, Arc<BodySourceMap>) {
173 let _p = profile("body_with_source_map_query"); 173 let _p = profile("body_with_source_map_query");
@@ -196,12 +196,12 @@ impl Body {
196 (Arc::new(body), Arc::new(source_map)) 196 (Arc::new(body), Arc::new(source_map))
197 } 197 }
198 198
199 pub(crate) fn body_query(db: &impl DefDatabase, def: DefWithBodyId) -> Arc<Body> { 199 pub(crate) fn body_query(db: &dyn DefDatabase, def: DefWithBodyId) -> Arc<Body> {
200 db.body_with_source_map(def).0 200 db.body_with_source_map(def).0
201 } 201 }
202 202
203 fn new( 203 fn new(
204 db: &impl DefDatabase, 204 db: &dyn DefDatabase,
205 def: DefWithBodyId, 205 def: DefWithBodyId,
206 expander: Expander, 206 expander: Expander,
207 params: Option<ast::ParamList>, 207 params: Option<ast::ParamList>,
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index 54b5591d3..6238de606 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -36,7 +36,7 @@ use crate::{
36}; 36};
37 37
38pub(super) fn lower( 38pub(super) fn lower(
39 db: &impl DefDatabase, 39 db: &dyn DefDatabase,
40 def: DefWithBodyId, 40 def: DefWithBodyId,
41 expander: Expander, 41 expander: Expander,
42 params: Option<ast::ParamList>, 42 params: Option<ast::ParamList>,
@@ -58,8 +58,8 @@ pub(super) fn lower(
58 .collect(params, body) 58 .collect(params, body)
59} 59}
60 60
61struct ExprCollector<DB> { 61struct ExprCollector<'a> {
62 db: DB, 62 db: &'a dyn DefDatabase,
63 def: DefWithBodyId, 63 def: DefWithBodyId,
64 expander: Expander, 64 expander: Expander,
65 65
@@ -67,10 +67,7 @@ struct ExprCollector<DB> {
67 source_map: BodySourceMap, 67 source_map: BodySourceMap,
68} 68}
69 69
70impl<'a, DB> ExprCollector<&'a DB> 70impl ExprCollector<'_> {
71where
72 DB: DefDatabase,
73{
74 fn collect( 71 fn collect(
75 mut self, 72 mut self,
76 param_list: Option<ast::ParamList>, 73 param_list: Option<ast::ParamList>,
diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs
index a58a7b21f..7c3db8869 100644
--- a/crates/ra_hir_def/src/body/scope.rs
+++ b/crates/ra_hir_def/src/body/scope.rs
@@ -45,7 +45,7 @@ pub struct ScopeData {
45} 45}
46 46
47impl ExprScopes { 47impl ExprScopes {
48 pub(crate) fn expr_scopes_query(db: &impl DefDatabase, def: DefWithBodyId) -> Arc<ExprScopes> { 48 pub(crate) fn expr_scopes_query(db: &dyn DefDatabase, def: DefWithBodyId) -> Arc<ExprScopes> {
49 let body = db.body(def); 49 let body = db.body(def);
50 Arc::new(ExprScopes::new(&*body)) 50 Arc::new(ExprScopes::new(&*body))
51 } 51 }
diff --git a/crates/ra_hir_def/src/child_by_source.rs b/crates/ra_hir_def/src/child_by_source.rs
index 8b6c773ee..7009f21d1 100644
--- a/crates/ra_hir_def/src/child_by_source.rs
+++ b/crates/ra_hir_def/src/child_by_source.rs
@@ -17,11 +17,11 @@ use crate::{
17}; 17};
18 18
19pub trait ChildBySource { 19pub trait ChildBySource {
20 fn child_by_source(&self, db: &impl DefDatabase) -> DynMap; 20 fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap;
21} 21}
22 22
23impl ChildBySource for TraitId { 23impl ChildBySource for TraitId {
24 fn child_by_source(&self, db: &impl DefDatabase) -> DynMap { 24 fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap {
25 let mut res = DynMap::default(); 25 let mut res = DynMap::default();
26 26
27 let data = db.trait_data(*self); 27 let data = db.trait_data(*self);
@@ -47,7 +47,7 @@ impl ChildBySource for TraitId {
47} 47}
48 48
49impl ChildBySource for ImplId { 49impl ChildBySource for ImplId {
50 fn child_by_source(&self, db: &impl DefDatabase) -> DynMap { 50 fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap {
51 let mut res = DynMap::default(); 51 let mut res = DynMap::default();
52 52
53 let data = db.impl_data(*self); 53 let data = db.impl_data(*self);
@@ -73,7 +73,7 @@ impl ChildBySource for ImplId {
73} 73}
74 74
75impl ChildBySource for ModuleId { 75impl ChildBySource for ModuleId {
76 fn child_by_source(&self, db: &impl DefDatabase) -> DynMap { 76 fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap {
77 let crate_def_map = db.crate_def_map(self.krate); 77 let crate_def_map = db.crate_def_map(self.krate);
78 let module_data = &crate_def_map[self.local_id]; 78 let module_data = &crate_def_map[self.local_id];
79 module_data.scope.child_by_source(db) 79 module_data.scope.child_by_source(db)
@@ -81,13 +81,13 @@ impl ChildBySource for ModuleId {
81} 81}
82 82
83impl ChildBySource for ItemScope { 83impl ChildBySource for ItemScope {
84 fn child_by_source(&self, db: &impl DefDatabase) -> DynMap { 84 fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap {
85 let mut res = DynMap::default(); 85 let mut res = DynMap::default();
86 self.declarations().for_each(|item| add_module_def(db, &mut res, item)); 86 self.declarations().for_each(|item| add_module_def(db, &mut res, item));
87 self.impls().for_each(|imp| add_impl(db, &mut res, imp)); 87 self.impls().for_each(|imp| add_impl(db, &mut res, imp));
88 return res; 88 return res;
89 89
90 fn add_module_def(db: &impl DefDatabase, map: &mut DynMap, item: ModuleDefId) { 90 fn add_module_def(db: &dyn DefDatabase, map: &mut DynMap, item: ModuleDefId) {
91 match item { 91 match item {
92 ModuleDefId::FunctionId(func) => { 92 ModuleDefId::FunctionId(func) => {
93 let src = func.lookup(db).source(db); 93 let src = func.lookup(db).source(db);
@@ -126,7 +126,7 @@ impl ChildBySource for ItemScope {
126 _ => (), 126 _ => (),
127 } 127 }
128 } 128 }
129 fn add_impl(db: &impl DefDatabase, map: &mut DynMap, imp: ImplId) { 129 fn add_impl(db: &dyn DefDatabase, map: &mut DynMap, imp: ImplId) {
130 let src = imp.lookup(db).source(db); 130 let src = imp.lookup(db).source(db);
131 map[keys::IMPL].insert(src, imp) 131 map[keys::IMPL].insert(src, imp)
132 } 132 }
@@ -134,7 +134,7 @@ impl ChildBySource for ItemScope {
134} 134}
135 135
136impl ChildBySource for VariantId { 136impl ChildBySource for VariantId {
137 fn child_by_source(&self, db: &impl DefDatabase) -> DynMap { 137 fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap {
138 let mut res = DynMap::default(); 138 let mut res = DynMap::default();
139 139
140 let arena_map = self.child_source(db); 140 let arena_map = self.child_source(db);
@@ -155,7 +155,7 @@ impl ChildBySource for VariantId {
155} 155}
156 156
157impl ChildBySource for EnumId { 157impl ChildBySource for EnumId {
158 fn child_by_source(&self, db: &impl DefDatabase) -> DynMap { 158 fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap {
159 let mut res = DynMap::default(); 159 let mut res = DynMap::default();
160 160
161 let arena_map = self.child_source(db); 161 let arena_map = self.child_source(db);
@@ -170,7 +170,7 @@ impl ChildBySource for EnumId {
170} 170}
171 171
172impl ChildBySource for DefWithBodyId { 172impl ChildBySource for DefWithBodyId {
173 fn child_by_source(&self, db: &impl DefDatabase) -> DynMap { 173 fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap {
174 let body = db.body(*self); 174 let body = db.body(*self);
175 body.item_scope.child_by_source(db) 175 body.item_scope.child_by_source(db)
176 } 176 }
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs
index c0b16b7fa..04bd4a305 100644
--- a/crates/ra_hir_def/src/data.rs
+++ b/crates/ra_hir_def/src/data.rs
@@ -105,7 +105,7 @@ pub struct TypeAliasData {
105 105
106impl TypeAliasData { 106impl TypeAliasData {
107 pub(crate) fn type_alias_data_query( 107 pub(crate) fn type_alias_data_query(
108 db: &impl DefDatabase, 108 db: &dyn DefDatabase,
109 typ: TypeAliasId, 109 typ: TypeAliasId,
110 ) -> Arc<TypeAliasData> { 110 ) -> Arc<TypeAliasData> {
111 let loc = typ.lookup(db); 111 let loc = typ.lookup(db);
@@ -127,7 +127,7 @@ pub struct TraitData {
127} 127}
128 128
129impl TraitData { 129impl TraitData {
130 pub(crate) fn trait_data_query(db: &impl DefDatabase, tr: TraitId) -> Arc<TraitData> { 130 pub(crate) fn trait_data_query(db: &dyn DefDatabase, tr: TraitId) -> Arc<TraitData> {
131 let src = tr.lookup(db).source(db); 131 let src = tr.lookup(db).source(db);
132 let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); 132 let name = src.value.name().map_or_else(Name::missing, |n| n.as_name());
133 let auto = src.value.is_auto(); 133 let auto = src.value.is_auto();
@@ -200,7 +200,7 @@ pub struct ImplData {
200} 200}
201 201
202impl ImplData { 202impl ImplData {
203 pub(crate) fn impl_data_query(db: &impl DefDatabase, id: ImplId) -> Arc<ImplData> { 203 pub(crate) fn impl_data_query(db: &dyn DefDatabase, id: ImplId) -> Arc<ImplData> {
204 let _p = profile("impl_data_query"); 204 let _p = profile("impl_data_query");
205 let impl_loc = id.lookup(db); 205 let impl_loc = id.lookup(db);
206 let src = impl_loc.source(db); 206 let src = impl_loc.source(db);
@@ -235,20 +235,20 @@ pub struct ConstData {
235} 235}
236 236
237impl ConstData { 237impl ConstData {
238 pub(crate) fn const_data_query(db: &impl DefDatabase, konst: ConstId) -> Arc<ConstData> { 238 pub(crate) fn const_data_query(db: &dyn DefDatabase, konst: ConstId) -> Arc<ConstData> {
239 let loc = konst.lookup(db); 239 let loc = konst.lookup(db);
240 let node = loc.source(db); 240 let node = loc.source(db);
241 let vis_default = RawVisibility::default_for_container(loc.container); 241 let vis_default = RawVisibility::default_for_container(loc.container);
242 Arc::new(ConstData::new(db, vis_default, node)) 242 Arc::new(ConstData::new(db, vis_default, node))
243 } 243 }
244 244
245 pub(crate) fn static_data_query(db: &impl DefDatabase, konst: StaticId) -> Arc<ConstData> { 245 pub(crate) fn static_data_query(db: &dyn DefDatabase, konst: StaticId) -> Arc<ConstData> {
246 let node = konst.lookup(db).source(db); 246 let node = konst.lookup(db).source(db);
247 Arc::new(ConstData::new(db, RawVisibility::private(), node)) 247 Arc::new(ConstData::new(db, RawVisibility::private(), node))
248 } 248 }
249 249
250 fn new<N: NameOwner + TypeAscriptionOwner + VisibilityOwner>( 250 fn new<N: NameOwner + TypeAscriptionOwner + VisibilityOwner>(
251 db: &impl DefDatabase, 251 db: &dyn DefDatabase,
252 vis_default: RawVisibility, 252 vis_default: RawVisibility,
253 node: InFile<N>, 253 node: InFile<N>,
254 ) -> ConstData { 254 ) -> ConstData {
@@ -261,7 +261,7 @@ impl ConstData {
261} 261}
262 262
263fn collect_impl_items_in_macros( 263fn collect_impl_items_in_macros(
264 db: &impl DefDatabase, 264 db: &dyn DefDatabase,
265 module_id: ModuleId, 265 module_id: ModuleId,
266 impl_def: &InFile<ast::ItemList>, 266 impl_def: &InFile<ast::ItemList>,
267 id: ImplId, 267 id: ImplId,
@@ -280,7 +280,7 @@ fn collect_impl_items_in_macros(
280} 280}
281 281
282fn collect_impl_items_in_macro( 282fn collect_impl_items_in_macro(
283 db: &impl DefDatabase, 283 db: &dyn DefDatabase,
284 expander: &mut Expander, 284 expander: &mut Expander,
285 m: ast::MacroCall, 285 m: ast::MacroCall,
286 id: ImplId, 286 id: ImplId,
@@ -312,7 +312,7 @@ fn collect_impl_items_in_macro(
312} 312}
313 313
314fn collect_impl_items( 314fn collect_impl_items(
315 db: &impl DefDatabase, 315 db: &dyn DefDatabase,
316 impl_items: impl Iterator<Item = ImplItem>, 316 impl_items: impl Iterator<Item = ImplItem>,
317 file_id: crate::HirFileId, 317 file_id: crate::HirFileId,
318 id: ImplId, 318 id: ImplId,
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs
index dcd377aae..7f8c1ea21 100644
--- a/crates/ra_hir_def/src/db.rs
+++ b/crates/ra_hir_def/src/db.rs
@@ -2,7 +2,7 @@
2use std::sync::Arc; 2use std::sync::Arc;
3 3
4use hir_expand::{db::AstDatabase, HirFileId}; 4use hir_expand::{db::AstDatabase, HirFileId};
5use ra_db::{salsa, CrateId, SourceDatabase}; 5use ra_db::{salsa, CrateId, SourceDatabase, Upcast};
6use ra_prof::profile; 6use ra_prof::profile;
7use ra_syntax::SmolStr; 7use ra_syntax::SmolStr;
8 8
@@ -43,7 +43,7 @@ pub trait InternDatabase: SourceDatabase {
43} 43}
44 44
45#[salsa::query_group(DefDatabaseStorage)] 45#[salsa::query_group(DefDatabaseStorage)]
46pub trait DefDatabase: InternDatabase + AstDatabase { 46pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
47 #[salsa::invoke(RawItems::raw_items_query)] 47 #[salsa::invoke(RawItems::raw_items_query)]
48 fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>; 48 fn raw_items(&self, file_id: HirFileId) -> Arc<RawItems>;
49 49
@@ -109,6 +109,12 @@ pub trait DefDatabase: InternDatabase + AstDatabase {
109 fn documentation(&self, def: AttrDefId) -> Option<Documentation>; 109 fn documentation(&self, def: AttrDefId) -> Option<Documentation>;
110} 110}
111 111
112// impl<T: DefDatabase> Upcast<dyn AstDatabase> for T {
113// fn upcast(&self) -> &dyn AstDatabase {
114// &*self
115// }
116// }
117
112fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> { 118fn crate_def_map_wait(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
113 let _p = profile("crate_def_map:wait"); 119 let _p = profile("crate_def_map:wait");
114 db.crate_def_map_query(krate) 120 db.crate_def_map_query(krate)
diff --git a/crates/ra_hir_def/src/docs.rs b/crates/ra_hir_def/src/docs.rs
index b29f142e3..0539a77d4 100644
--- a/crates/ra_hir_def/src/docs.rs
+++ b/crates/ra_hir_def/src/docs.rs
@@ -34,7 +34,7 @@ impl Documentation {
34 } 34 }
35 35
36 pub(crate) fn documentation_query( 36 pub(crate) fn documentation_query(
37 db: &impl DefDatabase, 37 db: &dyn DefDatabase,
38 def: AttrDefId, 38 def: AttrDefId,
39 ) -> Option<Documentation> { 39 ) -> Option<Documentation> {
40 match def { 40 match def {
@@ -60,7 +60,7 @@ impl Documentation {
60 docs_from_ast(&src.value[it.local_id]) 60 docs_from_ast(&src.value[it.local_id])
61 } 61 }
62 AttrDefId::TraitId(it) => docs_from_ast(&it.lookup(db).source(db).value), 62 AttrDefId::TraitId(it) => docs_from_ast(&it.lookup(db).source(db).value),
63 AttrDefId::MacroDefId(it) => docs_from_ast(&it.ast_id?.to_node(db)), 63 AttrDefId::MacroDefId(it) => docs_from_ast(&it.ast_id?.to_node(db.upcast())),
64 AttrDefId::ConstId(it) => docs_from_ast(&it.lookup(db).source(db).value), 64 AttrDefId::ConstId(it) => docs_from_ast(&it.lookup(db).source(db).value),
65 AttrDefId::StaticId(it) => docs_from_ast(&it.lookup(db).source(db).value), 65 AttrDefId::StaticId(it) => docs_from_ast(&it.lookup(db).source(db).value),
66 AttrDefId::FunctionId(it) => docs_from_ast(&it.lookup(db).source(db).value), 66 AttrDefId::FunctionId(it) => docs_from_ast(&it.lookup(db).source(db).value),
diff --git a/crates/ra_hir_def/src/find_path.rs b/crates/ra_hir_def/src/find_path.rs
index 07ca74ec3..d58ac6ba5 100644
--- a/crates/ra_hir_def/src/find_path.rs
+++ b/crates/ra_hir_def/src/find_path.rs
@@ -44,12 +44,12 @@ impl ModPath {
44 44
45/// Find a path that can be used to refer to a certain item. This can depend on 45/// Find a path that can be used to refer to a certain item. This can depend on
46/// *from where* you're referring to the item, hence the `from` parameter. 46/// *from where* you're referring to the item, hence the `from` parameter.
47pub fn find_path(db: &impl DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> { 47pub fn find_path(db: &dyn DefDatabase, item: ItemInNs, from: ModuleId) -> Option<ModPath> {
48 find_path_inner(db, item, from, MAX_PATH_LEN) 48 find_path_inner(db, item, from, MAX_PATH_LEN)
49} 49}
50 50
51fn find_path_inner( 51fn find_path_inner(
52 db: &impl DefDatabase, 52 db: &dyn DefDatabase,
53 item: ItemInNs, 53 item: ItemInNs,
54 from: ModuleId, 54 from: ModuleId,
55 max_len: usize, 55 max_len: usize,
@@ -165,7 +165,7 @@ fn select_best_path(old_path: ModPath, new_path: ModPath) -> ModPath {
165} 165}
166 166
167fn find_importable_locations( 167fn find_importable_locations(
168 db: &impl DefDatabase, 168 db: &dyn DefDatabase,
169 item: ItemInNs, 169 item: ItemInNs,
170 from: ModuleId, 170 from: ModuleId,
171) -> Vec<(ModuleId, Name)> { 171) -> Vec<(ModuleId, Name)> {
@@ -195,7 +195,7 @@ fn find_importable_locations(
195/// Note that the crate doesn't need to be the one in which the item is defined; 195/// Note that the crate doesn't need to be the one in which the item is defined;
196/// it might be re-exported in other crates. 196/// it might be re-exported in other crates.
197fn importable_locations_in_crate( 197fn importable_locations_in_crate(
198 db: &impl DefDatabase, 198 db: &dyn DefDatabase,
199 item: ItemInNs, 199 item: ItemInNs,
200 krate: CrateId, 200 krate: CrateId,
201) -> Vec<(ModuleId, Name, Visibility)> { 201) -> Vec<(ModuleId, Name, Visibility)> {
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs
index 519c60de0..24adc8153 100644
--- a/crates/ra_hir_def/src/generics.rs
+++ b/crates/ra_hir_def/src/generics.rs
@@ -69,7 +69,7 @@ type SourceMap = ArenaMap<LocalTypeParamId, Either<ast::TraitDef, ast::TypeParam
69 69
70impl GenericParams { 70impl GenericParams {
71 pub(crate) fn generic_params_query( 71 pub(crate) fn generic_params_query(
72 db: &impl DefDatabase, 72 db: &dyn DefDatabase,
73 def: GenericDefId, 73 def: GenericDefId,
74 ) -> Arc<GenericParams> { 74 ) -> Arc<GenericParams> {
75 let _p = profile("generic_params_query"); 75 let _p = profile("generic_params_query");
@@ -77,7 +77,7 @@ impl GenericParams {
77 Arc::new(params) 77 Arc::new(params)
78 } 78 }
79 79
80 fn new(db: &impl DefDatabase, def: GenericDefId) -> (GenericParams, InFile<SourceMap>) { 80 fn new(db: &dyn DefDatabase, def: GenericDefId) -> (GenericParams, InFile<SourceMap>) {
81 let mut generics = GenericParams { types: Arena::default(), where_predicates: Vec::new() }; 81 let mut generics = GenericParams { types: Arena::default(), where_predicates: Vec::new() };
82 let mut sm = ArenaMap::default(); 82 let mut sm = ArenaMap::default();
83 // FIXME: add `: Sized` bound for everything except for `Self` in traits 83 // FIXME: add `: Sized` bound for everything except for `Self` in traits
@@ -242,14 +242,14 @@ impl GenericParams {
242impl HasChildSource for GenericDefId { 242impl HasChildSource for GenericDefId {
243 type ChildId = LocalTypeParamId; 243 type ChildId = LocalTypeParamId;
244 type Value = Either<ast::TraitDef, ast::TypeParam>; 244 type Value = Either<ast::TraitDef, ast::TypeParam>;
245 fn child_source(&self, db: &impl DefDatabase) -> InFile<SourceMap> { 245 fn child_source(&self, db: &dyn DefDatabase) -> InFile<SourceMap> {
246 let (_, sm) = GenericParams::new(db, *self); 246 let (_, sm) = GenericParams::new(db, *self);
247 sm 247 sm
248 } 248 }
249} 249}
250 250
251impl ChildBySource for GenericDefId { 251impl ChildBySource for GenericDefId {
252 fn child_by_source(&self, db: &impl DefDatabase) -> DynMap { 252 fn child_by_source(&self, db: &dyn DefDatabase) -> DynMap {
253 let mut res = DynMap::default(); 253 let mut res = DynMap::default();
254 let arena_map = self.child_source(db); 254 let arena_map = self.child_source(db);
255 let arena_map = arena_map.as_ref(); 255 let arena_map = arena_map.as_ref();
diff --git a/crates/ra_hir_def/src/lang_item.rs b/crates/ra_hir_def/src/lang_item.rs
index 6de49730e..01b367278 100644
--- a/crates/ra_hir_def/src/lang_item.rs
+++ b/crates/ra_hir_def/src/lang_item.rs
@@ -77,7 +77,7 @@ impl LangItems {
77 } 77 }
78 78
79 /// Salsa query. This will look for lang items in a specific crate. 79 /// Salsa query. This will look for lang items in a specific crate.
80 pub(crate) fn crate_lang_items_query(db: &impl DefDatabase, krate: CrateId) -> Arc<LangItems> { 80 pub(crate) fn crate_lang_items_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<LangItems> {
81 let mut lang_items = LangItems::default(); 81 let mut lang_items = LangItems::default();
82 82
83 let crate_def_map = db.crate_def_map(krate); 83 let crate_def_map = db.crate_def_map(krate);
@@ -92,7 +92,7 @@ impl LangItems {
92 } 92 }
93 93
94 pub(crate) fn module_lang_items_query( 94 pub(crate) fn module_lang_items_query(
95 db: &impl DefDatabase, 95 db: &dyn DefDatabase,
96 module: ModuleId, 96 module: ModuleId,
97 ) -> Option<Arc<LangItems>> { 97 ) -> Option<Arc<LangItems>> {
98 let mut lang_items = LangItems::default(); 98 let mut lang_items = LangItems::default();
@@ -107,7 +107,7 @@ impl LangItems {
107 /// Salsa query. Look for a lang item, starting from the specified crate and recursively 107 /// Salsa query. Look for a lang item, starting from the specified crate and recursively
108 /// traversing its dependencies. 108 /// traversing its dependencies.
109 pub(crate) fn lang_item_query( 109 pub(crate) fn lang_item_query(
110 db: &impl DefDatabase, 110 db: &dyn DefDatabase,
111 start_crate: CrateId, 111 start_crate: CrateId,
112 item: SmolStr, 112 item: SmolStr,
113 ) -> Option<LangItemTarget> { 113 ) -> Option<LangItemTarget> {
@@ -122,7 +122,7 @@ impl LangItems {
122 .find_map(|dep| db.lang_item(dep.crate_id, item.clone())) 122 .find_map(|dep| db.lang_item(dep.crate_id, item.clone()))
123 } 123 }
124 124
125 fn collect_lang_items(&mut self, db: &impl DefDatabase, module: ModuleId) { 125 fn collect_lang_items(&mut self, db: &dyn DefDatabase, module: ModuleId) {
126 // Look for impl targets 126 // Look for impl targets
127 let def_map = db.crate_def_map(module.krate); 127 let def_map = db.crate_def_map(module.krate);
128 let module_data = &def_map[module.local_id]; 128 let module_data = &def_map[module.local_id];
@@ -152,7 +152,7 @@ impl LangItems {
152 152
153 fn collect_lang_item<T>( 153 fn collect_lang_item<T>(
154 &mut self, 154 &mut self,
155 db: &impl DefDatabase, 155 db: &dyn DefDatabase,
156 item: T, 156 item: T,
157 constructor: fn(T) -> LangItemTarget, 157 constructor: fn(T) -> LangItemTarget,
158 ) where 158 ) where
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index a3d617e1f..24f9eb9e0 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -47,8 +47,8 @@ mod marks;
47use std::hash::Hash; 47use std::hash::Hash;
48 48
49use hir_expand::{ 49use hir_expand::{
50 ast_id_map::FileAstId, db::AstDatabase, eager::expand_eager_macro, hygiene::Hygiene, AstId, 50 ast_id_map::FileAstId, eager::expand_eager_macro, hygiene::Hygiene, AstId, HirFileId, InFile,
51 HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, 51 MacroCallId, MacroCallKind, MacroDefId, MacroDefKind,
52}; 52};
53use ra_arena::{impl_arena_id, RawId}; 53use ra_arena::{impl_arena_id, RawId};
54use ra_db::{impl_intern_key, salsa, CrateId}; 54use ra_db::{impl_intern_key, salsa, CrateId};
@@ -87,14 +87,14 @@ macro_rules! impl_intern {
87 87
88 impl Intern for $loc { 88 impl Intern for $loc {
89 type ID = $id; 89 type ID = $id;
90 fn intern(self, db: &impl db::DefDatabase) -> $id { 90 fn intern(self, db: &dyn db::DefDatabase) -> $id {
91 db.$intern(self) 91 db.$intern(self)
92 } 92 }
93 } 93 }
94 94
95 impl Lookup for $id { 95 impl Lookup for $id {
96 type Data = $loc; 96 type Data = $loc;
97 fn lookup(&self, db: &impl db::DefDatabase) -> $loc { 97 fn lookup(&self, db: &dyn db::DefDatabase) -> $loc {
98 db.$lookup(*self) 98 db.$lookup(*self)
99 } 99 }
100 } 100 }
@@ -339,20 +339,20 @@ impl_froms!(VariantId: EnumVariantId, StructId, UnionId);
339 339
340trait Intern { 340trait Intern {
341 type ID; 341 type ID;
342 fn intern(self, db: &impl db::DefDatabase) -> Self::ID; 342 fn intern(self, db: &dyn db::DefDatabase) -> Self::ID;
343} 343}
344 344
345pub trait Lookup { 345pub trait Lookup {
346 type Data; 346 type Data;
347 fn lookup(&self, db: &impl db::DefDatabase) -> Self::Data; 347 fn lookup(&self, db: &dyn db::DefDatabase) -> Self::Data;
348} 348}
349 349
350pub trait HasModule { 350pub trait HasModule {
351 fn module(&self, db: &impl db::DefDatabase) -> ModuleId; 351 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId;
352} 352}
353 353
354impl HasModule for ContainerId { 354impl HasModule for ContainerId {
355 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 355 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
356 match *self { 356 match *self {
357 ContainerId::ModuleId(it) => it, 357 ContainerId::ModuleId(it) => it,
358 ContainerId::DefWithBodyId(it) => it.module(db), 358 ContainerId::DefWithBodyId(it) => it.module(db),
@@ -361,7 +361,7 @@ impl HasModule for ContainerId {
361} 361}
362 362
363impl HasModule for AssocContainerId { 363impl HasModule for AssocContainerId {
364 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 364 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
365 match *self { 365 match *self {
366 AssocContainerId::ContainerId(it) => it.module(db), 366 AssocContainerId::ContainerId(it) => it.module(db),
367 AssocContainerId::ImplId(it) => it.lookup(db).container.module(db), 367 AssocContainerId::ImplId(it) => it.lookup(db).container.module(db),
@@ -371,13 +371,13 @@ impl HasModule for AssocContainerId {
371} 371}
372 372
373impl<N: AstNode> HasModule for AssocItemLoc<N> { 373impl<N: AstNode> HasModule for AssocItemLoc<N> {
374 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 374 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
375 self.container.module(db) 375 self.container.module(db)
376 } 376 }
377} 377}
378 378
379impl HasModule for AdtId { 379impl HasModule for AdtId {
380 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 380 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
381 match self { 381 match self {
382 AdtId::StructId(it) => it.lookup(db).container, 382 AdtId::StructId(it) => it.lookup(db).container,
383 AdtId::UnionId(it) => it.lookup(db).container, 383 AdtId::UnionId(it) => it.lookup(db).container,
@@ -388,7 +388,7 @@ impl HasModule for AdtId {
388} 388}
389 389
390impl HasModule for DefWithBodyId { 390impl HasModule for DefWithBodyId {
391 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 391 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
392 match self { 392 match self {
393 DefWithBodyId::FunctionId(it) => it.lookup(db).module(db), 393 DefWithBodyId::FunctionId(it) => it.lookup(db).module(db),
394 DefWithBodyId::StaticId(it) => it.lookup(db).module(db), 394 DefWithBodyId::StaticId(it) => it.lookup(db).module(db),
@@ -398,7 +398,7 @@ impl HasModule for DefWithBodyId {
398} 398}
399 399
400impl HasModule for GenericDefId { 400impl HasModule for GenericDefId {
401 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 401 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
402 match self { 402 match self {
403 GenericDefId::FunctionId(it) => it.lookup(db).module(db), 403 GenericDefId::FunctionId(it) => it.lookup(db).module(db),
404 GenericDefId::AdtId(it) => it.module(db), 404 GenericDefId::AdtId(it) => it.module(db),
@@ -412,7 +412,7 @@ impl HasModule for GenericDefId {
412} 412}
413 413
414impl HasModule for StaticLoc { 414impl HasModule for StaticLoc {
415 fn module(&self, db: &impl db::DefDatabase) -> ModuleId { 415 fn module(&self, db: &dyn db::DefDatabase) -> ModuleId {
416 self.container.module(db) 416 self.container.module(db)
417 } 417 }
418} 418}
@@ -421,7 +421,7 @@ impl HasModule for StaticLoc {
421pub trait AsMacroCall { 421pub trait AsMacroCall {
422 fn as_call_id( 422 fn as_call_id(
423 &self, 423 &self,
424 db: &(impl db::DefDatabase + AstDatabase), 424 db: &dyn db::DefDatabase,
425 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, 425 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
426 ) -> Option<MacroCallId>; 426 ) -> Option<MacroCallId>;
427} 427}
@@ -429,11 +429,11 @@ pub trait AsMacroCall {
429impl AsMacroCall for InFile<&ast::MacroCall> { 429impl AsMacroCall for InFile<&ast::MacroCall> {
430 fn as_call_id( 430 fn as_call_id(
431 &self, 431 &self,
432 db: &(impl db::DefDatabase + AstDatabase), 432 db: &dyn db::DefDatabase,
433 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, 433 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
434 ) -> Option<MacroCallId> { 434 ) -> Option<MacroCallId> {
435 let ast_id = AstId::new(self.file_id, db.ast_id_map(self.file_id).ast_id(self.value)); 435 let ast_id = AstId::new(self.file_id, db.ast_id_map(self.file_id).ast_id(self.value));
436 let h = Hygiene::new(db, self.file_id); 436 let h = Hygiene::new(db.upcast(), self.file_id);
437 let path = path::ModPath::from_src(self.value.path()?, &h)?; 437 let path = path::ModPath::from_src(self.value.path()?, &h)?;
438 438
439 AstIdWithPath::new(ast_id.file_id, ast_id.value, path).as_call_id(db, resolver) 439 AstIdWithPath::new(ast_id.file_id, ast_id.value, path).as_call_id(db, resolver)
@@ -456,23 +456,23 @@ impl<T: ast::AstNode> AstIdWithPath<T> {
456impl AsMacroCall for AstIdWithPath<ast::MacroCall> { 456impl AsMacroCall for AstIdWithPath<ast::MacroCall> {
457 fn as_call_id( 457 fn as_call_id(
458 &self, 458 &self,
459 db: &impl AstDatabase, 459 db: &dyn db::DefDatabase,
460 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, 460 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
461 ) -> Option<MacroCallId> { 461 ) -> Option<MacroCallId> {
462 let def: MacroDefId = resolver(self.path.clone())?; 462 let def: MacroDefId = resolver(self.path.clone())?;
463 463
464 if let MacroDefKind::BuiltInEager(_) = def.kind { 464 if let MacroDefKind::BuiltInEager(_) = def.kind {
465 let macro_call = InFile::new(self.ast_id.file_id, self.ast_id.to_node(db)); 465 let macro_call = InFile::new(self.ast_id.file_id, self.ast_id.to_node(db.upcast()));
466 let hygiene = Hygiene::new(db, self.ast_id.file_id); 466 let hygiene = Hygiene::new(db.upcast(), self.ast_id.file_id);
467 467
468 Some( 468 Some(
469 expand_eager_macro(db, macro_call, def, &|path: ast::Path| { 469 expand_eager_macro(db.upcast(), macro_call, def, &|path: ast::Path| {
470 resolver(path::ModPath::from_src(path, &hygiene)?) 470 resolver(path::ModPath::from_src(path, &hygiene)?)
471 })? 471 })?
472 .into(), 472 .into(),
473 ) 473 )
474 } else { 474 } else {
475 Some(def.as_lazy_macro(db, MacroCallKind::FnLike(self.ast_id)).into()) 475 Some(def.as_lazy_macro(db.upcast(), MacroCallKind::FnLike(self.ast_id)).into())
476 } 476 }
477 } 477 }
478} 478}
@@ -480,10 +480,10 @@ impl AsMacroCall for AstIdWithPath<ast::MacroCall> {
480impl AsMacroCall for AstIdWithPath<ast::ModuleItem> { 480impl AsMacroCall for AstIdWithPath<ast::ModuleItem> {
481 fn as_call_id( 481 fn as_call_id(
482 &self, 482 &self,
483 db: &impl AstDatabase, 483 db: &dyn db::DefDatabase,
484 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, 484 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
485 ) -> Option<MacroCallId> { 485 ) -> Option<MacroCallId> {
486 let def = resolver(self.path.clone())?; 486 let def = resolver(self.path.clone())?;
487 Some(def.as_lazy_macro(db, MacroCallKind::Attr(self.ast_id)).into()) 487 Some(def.as_lazy_macro(db.upcast(), MacroCallKind::Attr(self.ast_id)).into())
488 } 488 }
489} 489}
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index 03515309e..be53313ee 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -151,16 +151,17 @@ impl ModuleOrigin {
151 151
152 /// Returns a node which defines this module. 152 /// Returns a node which defines this module.
153 /// That is, a file or a `mod foo {}` with items. 153 /// That is, a file or a `mod foo {}` with items.
154 fn definition_source(&self, db: &impl DefDatabase) -> InFile<ModuleSource> { 154 fn definition_source(&self, db: &dyn DefDatabase) -> InFile<ModuleSource> {
155 match self { 155 match self {
156 ModuleOrigin::File { definition, .. } | ModuleOrigin::CrateRoot { definition } => { 156 ModuleOrigin::File { definition, .. } | ModuleOrigin::CrateRoot { definition } => {
157 let file_id = *definition; 157 let file_id = *definition;
158 let sf = db.parse(file_id).tree(); 158 let sf = db.parse(file_id).tree();
159 InFile::new(file_id.into(), ModuleSource::SourceFile(sf)) 159 InFile::new(file_id.into(), ModuleSource::SourceFile(sf))
160 } 160 }
161 ModuleOrigin::Inline { definition } => { 161 ModuleOrigin::Inline { definition } => InFile::new(
162 InFile::new(definition.file_id, ModuleSource::Module(definition.to_node(db))) 162 definition.file_id,
163 } 163 ModuleSource::Module(definition.to_node(db.upcast())),
164 ),
164 } 165 }
165 } 166 }
166} 167}
@@ -176,7 +177,7 @@ pub struct ModuleData {
176} 177}
177 178
178impl CrateDefMap { 179impl CrateDefMap {
179 pub(crate) fn crate_def_map_query(db: &impl DefDatabase, krate: CrateId) -> Arc<CrateDefMap> { 180 pub(crate) fn crate_def_map_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<CrateDefMap> {
180 let _p = profile("crate_def_map_query").detail(|| { 181 let _p = profile("crate_def_map_query").detail(|| {
181 db.crate_graph()[krate] 182 db.crate_graph()[krate]
182 .display_name 183 .display_name
@@ -204,7 +205,7 @@ impl CrateDefMap {
204 205
205 pub fn add_diagnostics( 206 pub fn add_diagnostics(
206 &self, 207 &self,
207 db: &impl DefDatabase, 208 db: &dyn DefDatabase,
208 module: LocalModuleId, 209 module: LocalModuleId,
209 sink: &mut DiagnosticSink, 210 sink: &mut DiagnosticSink,
210 ) { 211 ) {
@@ -220,7 +221,7 @@ impl CrateDefMap {
220 221
221 pub(crate) fn resolve_path( 222 pub(crate) fn resolve_path(
222 &self, 223 &self,
223 db: &impl DefDatabase, 224 db: &dyn DefDatabase,
224 original_module: LocalModuleId, 225 original_module: LocalModuleId,
225 path: &ModPath, 226 path: &ModPath,
226 shadow: BuiltinShadowMode, 227 shadow: BuiltinShadowMode,
@@ -273,15 +274,15 @@ impl CrateDefMap {
273 274
274impl ModuleData { 275impl ModuleData {
275 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. 276 /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
276 pub fn definition_source(&self, db: &impl DefDatabase) -> InFile<ModuleSource> { 277 pub fn definition_source(&self, db: &dyn DefDatabase) -> InFile<ModuleSource> {
277 self.origin.definition_source(db) 278 self.origin.definition_source(db)
278 } 279 }
279 280
280 /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. 281 /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`.
281 /// `None` for the crate root or block. 282 /// `None` for the crate root or block.
282 pub fn declaration_source(&self, db: &impl DefDatabase) -> Option<InFile<ast::Module>> { 283 pub fn declaration_source(&self, db: &dyn DefDatabase) -> Option<InFile<ast::Module>> {
283 let decl = self.origin.declaration()?; 284 let decl = self.origin.declaration()?;
284 let value = decl.to_node(db); 285 let value = decl.to_node(db.upcast());
285 Some(InFile { file_id: decl.file_id, value }) 286 Some(InFile { file_id: decl.file_id, value })
286 } 287 }
287} 288}
@@ -311,7 +312,7 @@ mod diagnostics {
311 impl DefDiagnostic { 312 impl DefDiagnostic {
312 pub(super) fn add_to( 313 pub(super) fn add_to(
313 &self, 314 &self,
314 db: &impl DefDatabase, 315 db: &dyn DefDatabase,
315 target_module: LocalModuleId, 316 target_module: LocalModuleId,
316 sink: &mut DiagnosticSink, 317 sink: &mut DiagnosticSink,
317 ) { 318 ) {
@@ -320,7 +321,7 @@ mod diagnostics {
320 if *module != target_module { 321 if *module != target_module {
321 return; 322 return;
322 } 323 }
323 let decl = declaration.to_node(db); 324 let decl = declaration.to_node(db.upcast());
324 sink.push(UnresolvedModule { 325 sink.push(UnresolvedModule {
325 file: declaration.file_id, 326 file: declaration.file_id,
326 decl: AstPtr::new(&decl), 327 decl: AstPtr::new(&decl),
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index db9838cb5..7a042e69f 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -30,7 +30,7 @@ use crate::{
30 TraitLoc, TypeAliasLoc, UnionLoc, 30 TraitLoc, TypeAliasLoc, UnionLoc,
31}; 31};
32 32
33pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap { 33pub(super) fn collect_defs(db: &dyn DefDatabase, mut def_map: CrateDefMap) -> CrateDefMap {
34 let crate_graph = db.crate_graph(); 34 let crate_graph = db.crate_graph();
35 35
36 // populate external prelude 36 // populate external prelude
@@ -112,8 +112,8 @@ struct DeriveDirective {
112} 112}
113 113
114/// Walks the tree of module recursively 114/// Walks the tree of module recursively
115struct DefCollector<'a, DB> { 115struct DefCollector<'a> {
116 db: &'a DB, 116 db: &'a dyn DefDatabase,
117 def_map: CrateDefMap, 117 def_map: CrateDefMap,
118 glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility)>>, 118 glob_imports: FxHashMap<LocalModuleId, Vec<(LocalModuleId, Visibility)>>,
119 unresolved_imports: Vec<ImportDirective>, 119 unresolved_imports: Vec<ImportDirective>,
@@ -124,10 +124,7 @@ struct DefCollector<'a, DB> {
124 cfg_options: &'a CfgOptions, 124 cfg_options: &'a CfgOptions,
125} 125}
126 126
127impl<DB> DefCollector<'_, DB> 127impl DefCollector<'_> {
128where
129 DB: DefDatabase,
130{
131 fn collect(&mut self) { 128 fn collect(&mut self) {
132 let file_id = self.db.crate_graph()[self.def_map.krate].root_file_id; 129 let file_id = self.db.crate_graph()[self.def_map.krate].root_file_id;
133 let raw_items = self.db.raw_items(file_id.into()); 130 let raw_items = self.db.raw_items(file_id.into());
@@ -605,8 +602,8 @@ where
605} 602}
606 603
607/// Walks a single module, populating defs, imports and macros 604/// Walks a single module, populating defs, imports and macros
608struct ModCollector<'a, D> { 605struct ModCollector<'a, 'b> {
609 def_collector: D, 606 def_collector: &'a mut DefCollector<'b>,
610 macro_depth: usize, 607 macro_depth: usize,
611 module_id: LocalModuleId, 608 module_id: LocalModuleId,
612 file_id: HirFileId, 609 file_id: HirFileId,
@@ -614,10 +611,7 @@ struct ModCollector<'a, D> {
614 mod_dir: ModDir, 611 mod_dir: ModDir,
615} 612}
616 613
617impl<DB> ModCollector<'_, &'_ mut DefCollector<'_, DB>> 614impl ModCollector<'_, '_> {
618where
619 DB: DefDatabase,
620{
621 fn collect(&mut self, items: &[raw::RawItem]) { 615 fn collect(&mut self, items: &[raw::RawItem]) {
622 // Note: don't assert that inserted value is fresh: it's simply not true 616 // Note: don't assert that inserted value is fresh: it's simply not true
623 // for macros. 617 // for macros.
@@ -950,7 +944,7 @@ mod tests {
950 944
951 use super::*; 945 use super::*;
952 946
953 fn do_collect_defs(db: &impl DefDatabase, def_map: CrateDefMap) -> CrateDefMap { 947 fn do_collect_defs(db: &dyn DefDatabase, def_map: CrateDefMap) -> CrateDefMap {
954 let mut collector = DefCollector { 948 let mut collector = DefCollector {
955 db, 949 db,
956 def_map, 950 def_map,
diff --git a/crates/ra_hir_def/src/nameres/mod_resolution.rs b/crates/ra_hir_def/src/nameres/mod_resolution.rs
index 14fb8ba3a..386c5cade 100644
--- a/crates/ra_hir_def/src/nameres/mod_resolution.rs
+++ b/crates/ra_hir_def/src/nameres/mod_resolution.rs
@@ -40,12 +40,12 @@ impl ModDir {
40 40
41 pub(super) fn resolve_declaration( 41 pub(super) fn resolve_declaration(
42 &self, 42 &self,
43 db: &impl DefDatabase, 43 db: &dyn DefDatabase,
44 file_id: HirFileId, 44 file_id: HirFileId,
45 name: &Name, 45 name: &Name,
46 attr_path: Option<&SmolStr>, 46 attr_path: Option<&SmolStr>,
47 ) -> Result<(FileId, ModDir), RelativePathBuf> { 47 ) -> Result<(FileId, ModDir), RelativePathBuf> {
48 let file_id = file_id.original_file(db); 48 let file_id = file_id.original_file(db.upcast());
49 49
50 let mut candidate_files = Vec::new(); 50 let mut candidate_files = Vec::new();
51 match attr_to_path(attr_path) { 51 match attr_to_path(attr_path) {
diff --git a/crates/ra_hir_def/src/nameres/path_resolution.rs b/crates/ra_hir_def/src/nameres/path_resolution.rs
index c058e70aa..35a0a0c98 100644
--- a/crates/ra_hir_def/src/nameres/path_resolution.rs
+++ b/crates/ra_hir_def/src/nameres/path_resolution.rs
@@ -70,7 +70,7 @@ impl CrateDefMap {
70 70
71 pub(crate) fn resolve_visibility( 71 pub(crate) fn resolve_visibility(
72 &self, 72 &self,
73 db: &impl DefDatabase, 73 db: &dyn DefDatabase,
74 original_module: LocalModuleId, 74 original_module: LocalModuleId,
75 visibility: &RawVisibility, 75 visibility: &RawVisibility,
76 ) -> Option<Visibility> { 76 ) -> Option<Visibility> {
@@ -98,7 +98,7 @@ impl CrateDefMap {
98 // the result. 98 // the result.
99 pub(super) fn resolve_path_fp_with_macro( 99 pub(super) fn resolve_path_fp_with_macro(
100 &self, 100 &self,
101 db: &impl DefDatabase, 101 db: &dyn DefDatabase,
102 mode: ResolveMode, 102 mode: ResolveMode,
103 original_module: LocalModuleId, 103 original_module: LocalModuleId,
104 path: &ModPath, 104 path: &ModPath,
@@ -262,7 +262,7 @@ impl CrateDefMap {
262 262
263 fn resolve_name_in_module( 263 fn resolve_name_in_module(
264 &self, 264 &self,
265 db: &impl DefDatabase, 265 db: &dyn DefDatabase,
266 module: LocalModuleId, 266 module: LocalModuleId,
267 name: &Name, 267 name: &Name,
268 shadow: BuiltinShadowMode, 268 shadow: BuiltinShadowMode,
@@ -304,7 +304,7 @@ impl CrateDefMap {
304 from_crate_root.or(from_extern_prelude) 304 from_crate_root.or(from_extern_prelude)
305 } 305 }
306 306
307 fn resolve_in_prelude(&self, db: &impl DefDatabase, name: &Name) -> PerNs { 307 fn resolve_in_prelude(&self, db: &dyn DefDatabase, name: &Name) -> PerNs {
308 if let Some(prelude) = self.prelude { 308 if let Some(prelude) = self.prelude {
309 let keep; 309 let keep;
310 let def_map = if prelude.krate == self.krate { 310 let def_map = if prelude.krate == self.krate {
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs
index ea3c00da8..0e4931f58 100644
--- a/crates/ra_hir_def/src/nameres/raw.rs
+++ b/crates/ra_hir_def/src/nameres/raw.rs
@@ -9,7 +9,6 @@ use std::{ops::Index, sync::Arc};
9 9
10use hir_expand::{ 10use hir_expand::{
11 ast_id_map::AstIdMap, 11 ast_id_map::AstIdMap,
12 db::AstDatabase,
13 hygiene::Hygiene, 12 hygiene::Hygiene,
14 name::{AsName, Name}, 13 name::{AsName, Name},
15}; 14};
@@ -45,16 +44,13 @@ pub struct RawItems {
45} 44}
46 45
47impl RawItems { 46impl RawItems {
48 pub(crate) fn raw_items_query( 47 pub(crate) fn raw_items_query(db: &dyn DefDatabase, file_id: HirFileId) -> Arc<RawItems> {
49 db: &(impl DefDatabase + AstDatabase),
50 file_id: HirFileId,
51 ) -> Arc<RawItems> {
52 let _p = profile("raw_items_query"); 48 let _p = profile("raw_items_query");
53 let mut collector = RawItemsCollector { 49 let mut collector = RawItemsCollector {
54 raw_items: RawItems::default(), 50 raw_items: RawItems::default(),
55 source_ast_id_map: db.ast_id_map(file_id), 51 source_ast_id_map: db.ast_id_map(file_id),
56 file_id, 52 file_id,
57 hygiene: Hygiene::new(db, file_id), 53 hygiene: Hygiene::new(db.upcast(), file_id),
58 }; 54 };
59 if let Some(node) = db.parse_or_expand(file_id) { 55 if let Some(node) = db.parse_or_expand(file_id) {
60 if let Some(source_file) = ast::SourceFile::cast(node.clone()) { 56 if let Some(source_file) = ast::SourceFile::cast(node.clone()) {
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs
index 123fae72a..717506358 100644
--- a/crates/ra_hir_def/src/resolver.rs
+++ b/crates/ra_hir_def/src/resolver.rs
@@ -96,7 +96,7 @@ pub enum ValueNs {
96 96
97impl Resolver { 97impl Resolver {
98 /// Resolve known trait from std, like `std::futures::Future` 98 /// Resolve known trait from std, like `std::futures::Future`
99 pub fn resolve_known_trait(&self, db: &impl DefDatabase, path: &ModPath) -> Option<TraitId> { 99 pub fn resolve_known_trait(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<TraitId> {
100 let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?; 100 let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?;
101 match res { 101 match res {
102 ModuleDefId::TraitId(it) => Some(it), 102 ModuleDefId::TraitId(it) => Some(it),
@@ -105,7 +105,7 @@ impl Resolver {
105 } 105 }
106 106
107 /// Resolve known struct from std, like `std::boxed::Box` 107 /// Resolve known struct from std, like `std::boxed::Box`
108 pub fn resolve_known_struct(&self, db: &impl DefDatabase, path: &ModPath) -> Option<StructId> { 108 pub fn resolve_known_struct(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<StructId> {
109 let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?; 109 let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?;
110 match res { 110 match res {
111 ModuleDefId::AdtId(AdtId::StructId(it)) => Some(it), 111 ModuleDefId::AdtId(AdtId::StructId(it)) => Some(it),
@@ -114,7 +114,7 @@ impl Resolver {
114 } 114 }
115 115
116 /// Resolve known enum from std, like `std::result::Result` 116 /// Resolve known enum from std, like `std::result::Result`
117 pub fn resolve_known_enum(&self, db: &impl DefDatabase, path: &ModPath) -> Option<EnumId> { 117 pub fn resolve_known_enum(&self, db: &dyn DefDatabase, path: &ModPath) -> Option<EnumId> {
118 let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?; 118 let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?;
119 match res { 119 match res {
120 ModuleDefId::AdtId(AdtId::EnumId(it)) => Some(it), 120 ModuleDefId::AdtId(AdtId::EnumId(it)) => Some(it),
@@ -124,7 +124,7 @@ impl Resolver {
124 124
125 fn resolve_module_path( 125 fn resolve_module_path(
126 &self, 126 &self,
127 db: &impl DefDatabase, 127 db: &dyn DefDatabase,
128 path: &ModPath, 128 path: &ModPath,
129 shadow: BuiltinShadowMode, 129 shadow: BuiltinShadowMode,
130 ) -> PerNs { 130 ) -> PerNs {
@@ -139,13 +139,13 @@ impl Resolver {
139 module_res 139 module_res
140 } 140 }
141 141
142 pub fn resolve_module_path_in_items(&self, db: &impl DefDatabase, path: &ModPath) -> PerNs { 142 pub fn resolve_module_path_in_items(&self, db: &dyn DefDatabase, path: &ModPath) -> PerNs {
143 self.resolve_module_path(db, path, BuiltinShadowMode::Module) 143 self.resolve_module_path(db, path, BuiltinShadowMode::Module)
144 } 144 }
145 145
146 pub fn resolve_path_in_type_ns( 146 pub fn resolve_path_in_type_ns(
147 &self, 147 &self,
148 db: &impl DefDatabase, 148 db: &dyn DefDatabase,
149 path: &ModPath, 149 path: &ModPath,
150 ) -> Option<(TypeNs, Option<usize>)> { 150 ) -> Option<(TypeNs, Option<usize>)> {
151 let first_name = path.segments.first()?; 151 let first_name = path.segments.first()?;
@@ -222,7 +222,7 @@ impl Resolver {
222 222
223 pub fn resolve_path_in_type_ns_fully( 223 pub fn resolve_path_in_type_ns_fully(
224 &self, 224 &self,
225 db: &impl DefDatabase, 225 db: &dyn DefDatabase,
226 path: &ModPath, 226 path: &ModPath,
227 ) -> Option<TypeNs> { 227 ) -> Option<TypeNs> {
228 let (res, unresolved) = self.resolve_path_in_type_ns(db, path)?; 228 let (res, unresolved) = self.resolve_path_in_type_ns(db, path)?;
@@ -234,7 +234,7 @@ impl Resolver {
234 234
235 pub fn resolve_visibility( 235 pub fn resolve_visibility(
236 &self, 236 &self,
237 db: &impl DefDatabase, 237 db: &dyn DefDatabase,
238 visibility: &RawVisibility, 238 visibility: &RawVisibility,
239 ) -> Option<Visibility> { 239 ) -> Option<Visibility> {
240 match visibility { 240 match visibility {
@@ -251,7 +251,7 @@ impl Resolver {
251 251
252 pub fn resolve_path_in_value_ns( 252 pub fn resolve_path_in_value_ns(
253 &self, 253 &self,
254 db: &impl DefDatabase, 254 db: &dyn DefDatabase,
255 path: &ModPath, 255 path: &ModPath,
256 ) -> Option<ResolveValueResult> { 256 ) -> Option<ResolveValueResult> {
257 let n_segments = path.segments.len(); 257 let n_segments = path.segments.len();
@@ -367,7 +367,7 @@ impl Resolver {
367 367
368 pub fn resolve_path_in_value_ns_fully( 368 pub fn resolve_path_in_value_ns_fully(
369 &self, 369 &self,
370 db: &impl DefDatabase, 370 db: &dyn DefDatabase,
371 path: &ModPath, 371 path: &ModPath,
372 ) -> Option<ValueNs> { 372 ) -> Option<ValueNs> {
373 match self.resolve_path_in_value_ns(db, path)? { 373 match self.resolve_path_in_value_ns(db, path)? {
@@ -378,7 +378,7 @@ impl Resolver {
378 378
379 pub fn resolve_path_as_macro( 379 pub fn resolve_path_as_macro(
380 &self, 380 &self,
381 db: &impl DefDatabase, 381 db: &dyn DefDatabase,
382 path: &ModPath, 382 path: &ModPath,
383 ) -> Option<MacroDefId> { 383 ) -> Option<MacroDefId> {
384 // Search item scope legacy macro first 384 // Search item scope legacy macro first
@@ -390,13 +390,13 @@ impl Resolver {
390 item_map.resolve_path(db, module, &path, BuiltinShadowMode::Other).0.take_macros() 390 item_map.resolve_path(db, module, &path, BuiltinShadowMode::Other).0.take_macros()
391 } 391 }
392 392
393 pub fn process_all_names(&self, db: &impl DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) { 393 pub fn process_all_names(&self, db: &dyn DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) {
394 for scope in self.scopes.iter().rev() { 394 for scope in self.scopes.iter().rev() {
395 scope.process_names(db, f); 395 scope.process_names(db, f);
396 } 396 }
397 } 397 }
398 398
399 pub fn traits_in_scope(&self, db: &impl DefDatabase) -> FxHashSet<TraitId> { 399 pub fn traits_in_scope(&self, db: &dyn DefDatabase) -> FxHashSet<TraitId> {
400 let mut traits = FxHashSet::default(); 400 let mut traits = FxHashSet::default();
401 for scope in &self.scopes { 401 for scope in &self.scopes {
402 if let Scope::ModuleScope(m) = scope { 402 if let Scope::ModuleScope(m) = scope {
@@ -474,7 +474,7 @@ pub enum ScopeDef {
474} 474}
475 475
476impl Scope { 476impl Scope {
477 fn process_names(&self, db: &impl DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) { 477 fn process_names(&self, db: &dyn DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) {
478 match self { 478 match self {
479 Scope::ModuleScope(m) => { 479 Scope::ModuleScope(m) => {
480 // FIXME: should we provide `self` here? 480 // FIXME: should we provide `self` here?
@@ -534,13 +534,13 @@ impl Scope {
534} 534}
535 535
536// needs arbitrary_self_types to be a method... or maybe move to the def? 536// needs arbitrary_self_types to be a method... or maybe move to the def?
537pub fn resolver_for_expr(db: &impl DefDatabase, owner: DefWithBodyId, expr_id: ExprId) -> Resolver { 537pub fn resolver_for_expr(db: &dyn DefDatabase, owner: DefWithBodyId, expr_id: ExprId) -> Resolver {
538 let scopes = db.expr_scopes(owner); 538 let scopes = db.expr_scopes(owner);
539 resolver_for_scope(db, owner, scopes.scope_for(expr_id)) 539 resolver_for_scope(db, owner, scopes.scope_for(expr_id))
540} 540}
541 541
542pub fn resolver_for_scope( 542pub fn resolver_for_scope(
543 db: &impl DefDatabase, 543 db: &dyn DefDatabase,
544 owner: DefWithBodyId, 544 owner: DefWithBodyId,
545 scope_id: Option<ScopeId>, 545 scope_id: Option<ScopeId>,
546) -> Resolver { 546) -> Resolver {
@@ -560,7 +560,7 @@ impl Resolver {
560 self 560 self
561 } 561 }
562 562
563 fn push_generic_params_scope(self, db: &impl DefDatabase, def: GenericDefId) -> Resolver { 563 fn push_generic_params_scope(self, db: &dyn DefDatabase, def: GenericDefId) -> Resolver {
564 let params = db.generic_params(def); 564 let params = db.generic_params(def);
565 self.push_scope(Scope::GenericParams { def, params }) 565 self.push_scope(Scope::GenericParams { def, params })
566 } 566 }
@@ -593,24 +593,24 @@ impl Resolver {
593 593
594pub trait HasResolver: Copy { 594pub trait HasResolver: Copy {
595 /// Builds a resolver for type references inside this def. 595 /// Builds a resolver for type references inside this def.
596 fn resolver(self, db: &impl DefDatabase) -> Resolver; 596 fn resolver(self, db: &dyn DefDatabase) -> Resolver;
597} 597}
598 598
599impl HasResolver for ModuleId { 599impl HasResolver for ModuleId {
600 fn resolver(self, db: &impl DefDatabase) -> Resolver { 600 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
601 let def_map = db.crate_def_map(self.krate); 601 let def_map = db.crate_def_map(self.krate);
602 Resolver::default().push_module_scope(def_map, self.local_id) 602 Resolver::default().push_module_scope(def_map, self.local_id)
603 } 603 }
604} 604}
605 605
606impl HasResolver for TraitId { 606impl HasResolver for TraitId {
607 fn resolver(self, db: &impl DefDatabase) -> Resolver { 607 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
608 self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into()) 608 self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into())
609 } 609 }
610} 610}
611 611
612impl<T: Into<AdtId> + Copy> HasResolver for T { 612impl<T: Into<AdtId> + Copy> HasResolver for T {
613 fn resolver(self, db: &impl DefDatabase) -> Resolver { 613 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
614 let def = self.into(); 614 let def = self.into();
615 def.module(db) 615 def.module(db)
616 .resolver(db) 616 .resolver(db)
@@ -620,31 +620,31 @@ impl<T: Into<AdtId> + Copy> HasResolver for T {
620} 620}
621 621
622impl HasResolver for FunctionId { 622impl HasResolver for FunctionId {
623 fn resolver(self, db: &impl DefDatabase) -> Resolver { 623 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
624 self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into()) 624 self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into())
625 } 625 }
626} 626}
627 627
628impl HasResolver for ConstId { 628impl HasResolver for ConstId {
629 fn resolver(self, db: &impl DefDatabase) -> Resolver { 629 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
630 self.lookup(db).container.resolver(db) 630 self.lookup(db).container.resolver(db)
631 } 631 }
632} 632}
633 633
634impl HasResolver for StaticId { 634impl HasResolver for StaticId {
635 fn resolver(self, db: &impl DefDatabase) -> Resolver { 635 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
636 self.lookup(db).container.resolver(db) 636 self.lookup(db).container.resolver(db)
637 } 637 }
638} 638}
639 639
640impl HasResolver for TypeAliasId { 640impl HasResolver for TypeAliasId {
641 fn resolver(self, db: &impl DefDatabase) -> Resolver { 641 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
642 self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into()) 642 self.lookup(db).container.resolver(db).push_generic_params_scope(db, self.into())
643 } 643 }
644} 644}
645 645
646impl HasResolver for ImplId { 646impl HasResolver for ImplId {
647 fn resolver(self, db: &impl DefDatabase) -> Resolver { 647 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
648 self.lookup(db) 648 self.lookup(db)
649 .container 649 .container
650 .resolver(db) 650 .resolver(db)
@@ -654,7 +654,7 @@ impl HasResolver for ImplId {
654} 654}
655 655
656impl HasResolver for DefWithBodyId { 656impl HasResolver for DefWithBodyId {
657 fn resolver(self, db: &impl DefDatabase) -> Resolver { 657 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
658 match self { 658 match self {
659 DefWithBodyId::ConstId(c) => c.resolver(db), 659 DefWithBodyId::ConstId(c) => c.resolver(db),
660 DefWithBodyId::FunctionId(f) => f.resolver(db), 660 DefWithBodyId::FunctionId(f) => f.resolver(db),
@@ -664,7 +664,7 @@ impl HasResolver for DefWithBodyId {
664} 664}
665 665
666impl HasResolver for ContainerId { 666impl HasResolver for ContainerId {
667 fn resolver(self, db: &impl DefDatabase) -> Resolver { 667 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
668 match self { 668 match self {
669 ContainerId::ModuleId(it) => it.resolver(db), 669 ContainerId::ModuleId(it) => it.resolver(db),
670 ContainerId::DefWithBodyId(it) => it.module(db).resolver(db), 670 ContainerId::DefWithBodyId(it) => it.module(db).resolver(db),
@@ -673,7 +673,7 @@ impl HasResolver for ContainerId {
673} 673}
674 674
675impl HasResolver for AssocContainerId { 675impl HasResolver for AssocContainerId {
676 fn resolver(self, db: &impl DefDatabase) -> Resolver { 676 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
677 match self { 677 match self {
678 AssocContainerId::ContainerId(it) => it.resolver(db), 678 AssocContainerId::ContainerId(it) => it.resolver(db),
679 AssocContainerId::TraitId(it) => it.resolver(db), 679 AssocContainerId::TraitId(it) => it.resolver(db),
@@ -683,7 +683,7 @@ impl HasResolver for AssocContainerId {
683} 683}
684 684
685impl HasResolver for GenericDefId { 685impl HasResolver for GenericDefId {
686 fn resolver(self, db: &impl DefDatabase) -> Resolver { 686 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
687 match self { 687 match self {
688 GenericDefId::FunctionId(inner) => inner.resolver(db), 688 GenericDefId::FunctionId(inner) => inner.resolver(db),
689 GenericDefId::AdtId(adt) => adt.resolver(db), 689 GenericDefId::AdtId(adt) => adt.resolver(db),
@@ -697,7 +697,7 @@ impl HasResolver for GenericDefId {
697} 697}
698 698
699impl HasResolver for VariantId { 699impl HasResolver for VariantId {
700 fn resolver(self, db: &impl DefDatabase) -> Resolver { 700 fn resolver(self, db: &dyn DefDatabase) -> Resolver {
701 match self { 701 match self {
702 VariantId::EnumVariantId(it) => it.parent.resolver(db), 702 VariantId::EnumVariantId(it) => it.parent.resolver(db),
703 VariantId::StructId(it) => it.resolver(db), 703 VariantId::StructId(it) => it.resolver(db),
diff --git a/crates/ra_hir_def/src/src.rs b/crates/ra_hir_def/src/src.rs
index 499375b80..46e90da70 100644
--- a/crates/ra_hir_def/src/src.rs
+++ b/crates/ra_hir_def/src/src.rs
@@ -8,14 +8,14 @@ use crate::{db::DefDatabase, AssocItemLoc, ItemLoc};
8 8
9pub trait HasSource { 9pub trait HasSource {
10 type Value; 10 type Value;
11 fn source(&self, db: &impl DefDatabase) -> InFile<Self::Value>; 11 fn source(&self, db: &dyn DefDatabase) -> InFile<Self::Value>;
12} 12}
13 13
14impl<N: AstNode> HasSource for AssocItemLoc<N> { 14impl<N: AstNode> HasSource for AssocItemLoc<N> {
15 type Value = N; 15 type Value = N;
16 16
17 fn source(&self, db: &impl DefDatabase) -> InFile<N> { 17 fn source(&self, db: &dyn DefDatabase) -> InFile<N> {
18 let node = self.ast_id.to_node(db); 18 let node = self.ast_id.to_node(db.upcast());
19 InFile::new(self.ast_id.file_id, node) 19 InFile::new(self.ast_id.file_id, node)
20 } 20 }
21} 21}
@@ -23,8 +23,8 @@ impl<N: AstNode> HasSource for AssocItemLoc<N> {
23impl<N: AstNode> HasSource for ItemLoc<N> { 23impl<N: AstNode> HasSource for ItemLoc<N> {
24 type Value = N; 24 type Value = N;
25 25
26 fn source(&self, db: &impl DefDatabase) -> InFile<N> { 26 fn source(&self, db: &dyn DefDatabase) -> InFile<N> {
27 let node = self.ast_id.to_node(db); 27 let node = self.ast_id.to_node(db.upcast());
28 InFile::new(self.ast_id.file_id, node) 28 InFile::new(self.ast_id.file_id, node)
29 } 29 }
30} 30}
@@ -32,5 +32,5 @@ impl<N: AstNode> HasSource for ItemLoc<N> {
32pub trait HasChildSource { 32pub trait HasChildSource {
33 type ChildId; 33 type ChildId;
34 type Value; 34 type Value;
35 fn child_source(&self, db: &impl DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>>; 35 fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>>;
36} 36}
diff --git a/crates/ra_hir_def/src/test_db.rs b/crates/ra_hir_def/src/test_db.rs
index 0756916a8..eb83dee79 100644
--- a/crates/ra_hir_def/src/test_db.rs
+++ b/crates/ra_hir_def/src/test_db.rs
@@ -5,8 +5,12 @@ use std::{
5 sync::{Arc, Mutex}, 5 sync::{Arc, Mutex},
6}; 6};
7 7
8use hir_expand::db::AstDatabase;
9use ra_db::{
10 salsa, CrateId, ExternSourceId, FileId, FileLoader, FileLoaderDelegate, RelativePath, Upcast,
11};
12
8use crate::db::DefDatabase; 13use crate::db::DefDatabase;
9use ra_db::{salsa, CrateId, ExternSourceId, FileId, FileLoader, FileLoaderDelegate, RelativePath};
10 14
11#[salsa::database( 15#[salsa::database(
12 ra_db::SourceDatabaseExtStorage, 16 ra_db::SourceDatabaseExtStorage,
@@ -21,6 +25,18 @@ pub struct TestDB {
21 events: Mutex<Option<Vec<salsa::Event<TestDB>>>>, 25 events: Mutex<Option<Vec<salsa::Event<TestDB>>>>,
22} 26}
23 27
28impl Upcast<dyn AstDatabase> for TestDB {
29 fn upcast(&self) -> &(dyn AstDatabase + 'static) {
30 &*self
31 }
32}
33
34impl Upcast<dyn DefDatabase> for TestDB {
35 fn upcast(&self) -> &(dyn DefDatabase + 'static) {
36 &*self
37 }
38}
39
24impl salsa::Database for TestDB { 40impl salsa::Database for TestDB {
25 fn salsa_runtime(&self) -> &salsa::Runtime<Self> { 41 fn salsa_runtime(&self) -> &salsa::Runtime<Self> {
26 &self.runtime 42 &self.runtime
diff --git a/crates/ra_hir_def/src/visibility.rs b/crates/ra_hir_def/src/visibility.rs
index e0c59e905..62513873e 100644
--- a/crates/ra_hir_def/src/visibility.rs
+++ b/crates/ra_hir_def/src/visibility.rs
@@ -33,22 +33,22 @@ impl RawVisibility {
33 } 33 }
34 34
35 pub(crate) fn from_ast_with_default( 35 pub(crate) fn from_ast_with_default(
36 db: &impl DefDatabase, 36 db: &dyn DefDatabase,
37 default: RawVisibility, 37 default: RawVisibility,
38 node: InFile<Option<ast::Visibility>>, 38 node: InFile<Option<ast::Visibility>>,
39 ) -> RawVisibility { 39 ) -> RawVisibility {
40 Self::from_ast_with_hygiene_and_default( 40 Self::from_ast_with_hygiene_and_default(
41 node.value, 41 node.value,
42 default, 42 default,
43 &Hygiene::new(db, node.file_id), 43 &Hygiene::new(db.upcast(), node.file_id),
44 ) 44 )
45 } 45 }
46 46
47 pub(crate) fn from_ast( 47 pub(crate) fn from_ast(
48 db: &impl DefDatabase, 48 db: &dyn DefDatabase,
49 node: InFile<Option<ast::Visibility>>, 49 node: InFile<Option<ast::Visibility>>,
50 ) -> RawVisibility { 50 ) -> RawVisibility {
51 Self::from_ast_with_hygiene(node.value, &Hygiene::new(db, node.file_id)) 51 Self::from_ast_with_hygiene(node.value, &Hygiene::new(db.upcast(), node.file_id))
52 } 52 }
53 53
54 pub(crate) fn from_ast_with_hygiene( 54 pub(crate) fn from_ast_with_hygiene(
@@ -90,7 +90,7 @@ impl RawVisibility {
90 90
91 pub fn resolve( 91 pub fn resolve(
92 &self, 92 &self,
93 db: &impl DefDatabase, 93 db: &dyn DefDatabase,
94 resolver: &crate::resolver::Resolver, 94 resolver: &crate::resolver::Resolver,
95 ) -> Visibility { 95 ) -> Visibility {
96 // we fall back to public visibility (i.e. fail open) if the path can't be resolved 96 // we fall back to public visibility (i.e. fail open) if the path can't be resolved
@@ -108,7 +108,7 @@ pub enum Visibility {
108} 108}
109 109
110impl Visibility { 110impl Visibility {
111 pub fn is_visible_from(self, db: &impl DefDatabase, from_module: ModuleId) -> bool { 111 pub fn is_visible_from(self, db: &dyn DefDatabase, from_module: ModuleId) -> bool {
112 let to_module = match self { 112 let to_module = match self {
113 Visibility::Module(m) => m, 113 Visibility::Module(m) => m,
114 Visibility::Public => return true, 114 Visibility::Public => return true,