aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/attr.rs108
-rw-r--r--crates/ra_hir_def/src/body.rs5
-rw-r--r--crates/ra_hir_def/src/data.rs17
-rw-r--r--crates/ra_hir_def/src/db.rs5
-rw-r--r--crates/ra_hir_def/src/docs.rs7
-rw-r--r--crates/ra_hir_def/src/lang_item.rs4
-rw-r--r--crates/ra_hir_def/src/lib.rs82
-rw-r--r--crates/ra_hir_def/src/nameres.rs37
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs63
-rw-r--r--crates/ra_hir_def/src/nameres/raw.rs14
-rw-r--r--crates/ra_hir_def/src/path.rs13
-rw-r--r--crates/ra_hir_def/src/per_ns.rs10
-rw-r--r--crates/ra_hir_def/src/resolver.rs4
-rw-r--r--crates/ra_hir_def/src/type_ref.rs8
14 files changed, 189 insertions, 188 deletions
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs
index 48ce8cd93..53456fc08 100644
--- a/crates/ra_hir_def/src/attr.rs
+++ b/crates/ra_hir_def/src/attr.rs
@@ -2,9 +2,8 @@
2 2
3use std::{ops, sync::Arc}; 3use std::{ops, sync::Arc};
4 4
5use hir_expand::{either::Either, hygiene::Hygiene, AstId}; 5use hir_expand::{either::Either, hygiene::Hygiene, AstId, Source};
6use mbe::ast_to_token_tree; 6use mbe::ast_to_token_tree;
7use ra_cfg::CfgOptions;
8use ra_syntax::{ 7use ra_syntax::{
9 ast::{self, AstNode, AttrsOwner}, 8 ast::{self, AstNode, AttrsOwner},
10 SmolStr, 9 SmolStr,
@@ -40,50 +39,53 @@ impl Attrs {
40 Some(it) => it, 39 Some(it) => it,
41 None => return Attrs::default(), 40 None => return Attrs::default(),
42 }; 41 };
43 let hygiene = Hygiene::new(db, src.file_id); 42 Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner))
44 Attr::from_attrs_owner(&src.value, &hygiene)
45 } 43 }
46 AttrDefId::StructFieldId(it) => { 44 AttrDefId::StructFieldId(it) => {
47 let src = it.parent.child_source(db); 45 let src = it.parent.child_source(db);
48 match &src.value[it.local_id] { 46 match &src.value[it.local_id] {
49 Either::A(_tuple) => Attrs::default(), 47 Either::A(_tuple) => Attrs::default(),
50 Either::B(record) => { 48 Either::B(record) => Attrs::from_attrs_owner(db, src.with_value(record)),
51 let hygiene = Hygiene::new(db, src.file_id);
52 Attr::from_attrs_owner(record, &hygiene)
53 }
54 } 49 }
55 } 50 }
56 AttrDefId::EnumVariantId(it) => { 51 AttrDefId::EnumVariantId(var_id) => {
57 let src = it.parent.child_source(db); 52 let src = var_id.parent.child_source(db);
58 let hygiene = Hygiene::new(db, src.file_id); 53 let src = src.as_ref().map(|it| &it[var_id.local_id]);
59 Attr::from_attrs_owner(&src.value[it.local_id], &hygiene) 54 Attrs::from_attrs_owner(db, src.map(|it| it as &dyn AttrsOwner))
60 } 55 }
61 AttrDefId::AdtId(it) => match it { 56 AttrDefId::AdtId(it) => match it {
62 AdtId::StructId(it) => attrs_from_ast(it.0.lookup_intern(db).ast_id, db), 57 AdtId::StructId(it) => attrs_from_ast(it.0.lookup_intern(db).ast_id, db),
63 AdtId::EnumId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), 58 AdtId::EnumId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db),
64 AdtId::UnionId(it) => attrs_from_ast(it.0.lookup_intern(db).ast_id, db), 59 AdtId::UnionId(it) => attrs_from_ast(it.0.lookup_intern(db).ast_id, db),
65 }, 60 },
66 AttrDefId::StaticId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db),
67 AttrDefId::TraitId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), 61 AttrDefId::TraitId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db),
68 AttrDefId::MacroDefId(it) => attrs_from_ast(it.ast_id, db), 62 AttrDefId::MacroDefId(it) => attrs_from_ast(it.ast_id, db),
69 AttrDefId::ImplId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db), 63 AttrDefId::ImplId(it) => attrs_from_ast(it.lookup_intern(db).ast_id, db),
70 AttrDefId::ConstId(it) => attrs_from_loc(it.lookup(db), db), 64 AttrDefId::ConstId(it) => attrs_from_loc(it.lookup(db), db),
65 AttrDefId::StaticId(it) => attrs_from_loc(it.lookup(db), db),
71 AttrDefId::FunctionId(it) => attrs_from_loc(it.lookup(db), db), 66 AttrDefId::FunctionId(it) => attrs_from_loc(it.lookup(db), db),
72 AttrDefId::TypeAliasId(it) => attrs_from_loc(it.lookup(db), db), 67 AttrDefId::TypeAliasId(it) => attrs_from_loc(it.lookup(db), db),
73 } 68 }
74 } 69 }
75 70
76 pub fn has_atom(&self, atom: &str) -> bool { 71 fn from_attrs_owner(db: &impl DefDatabase, owner: Source<&dyn AttrsOwner>) -> Attrs {
77 self.iter().any(|it| it.is_simple_atom(atom)) 72 let hygiene = Hygiene::new(db, owner.file_id);
73 Attrs::new(owner.value, &hygiene)
78 } 74 }
79 75
80 pub fn find_string_value(&self, key: &str) -> Option<SmolStr> { 76 pub(crate) fn new(owner: &dyn AttrsOwner, hygiene: &Hygiene) -> Attrs {
81 self.iter().filter(|attr| attr.is_simple_atom(key)).find_map(|attr| { 77 let mut attrs = owner.attrs().peekable();
82 match attr.input.as_ref()? { 78 let entries = if attrs.peek().is_none() {
83 AttrInput::Literal(it) => Some(it.clone()), 79 // Avoid heap allocation
84 _ => None, 80 None
85 } 81 } else {
86 }) 82 Some(attrs.flat_map(|ast| Attr::from_src(ast, hygiene)).collect())
83 };
84 Attrs { entries }
85 }
86
87 pub fn by_key(&self, key: &'static str) -> AttrQuery<'_> {
88 AttrQuery { attrs: self, key }
87 } 89 }
88} 90}
89 91
@@ -100,7 +102,7 @@ pub enum AttrInput {
100} 102}
101 103
102impl Attr { 104impl Attr {
103 pub(crate) fn from_src(ast: ast::Attr, hygiene: &Hygiene) -> Option<Attr> { 105 fn from_src(ast: ast::Attr, hygiene: &Hygiene) -> Option<Attr> {
104 let path = Path::from_src(ast.path()?, hygiene)?; 106 let path = Path::from_src(ast.path()?, hygiene)?;
105 let input = match ast.input() { 107 let input = match ast.input() {
106 None => None, 108 None => None,
@@ -116,46 +118,37 @@ impl Attr {
116 118
117 Some(Attr { path, input }) 119 Some(Attr { path, input })
118 } 120 }
121}
119 122
120 pub fn from_attrs_owner(owner: &dyn AttrsOwner, hygiene: &Hygiene) -> Attrs { 123pub struct AttrQuery<'a> {
121 let mut attrs = owner.attrs().peekable(); 124 attrs: &'a Attrs,
122 let entries = if attrs.peek().is_none() { 125 key: &'static str,
123 // Avoid heap allocation 126}
124 None
125 } else {
126 Some(attrs.flat_map(|ast| Attr::from_src(ast, hygiene)).collect())
127 };
128 Attrs { entries }
129 }
130 127
131 pub fn is_simple_atom(&self, name: &str) -> bool { 128impl<'a> AttrQuery<'a> {
132 // FIXME: Avoid cloning 129 pub fn tt_values(self) -> impl Iterator<Item = &'a Subtree> {
133 self.path.as_ident().map_or(false, |s| s.to_string() == name) 130 self.attrs().filter_map(|attr| match attr.input.as_ref()? {
131 AttrInput::TokenTree(it) => Some(it),
132 _ => None,
133 })
134 } 134 }
135 135
136 // FIXME: handle cfg_attr :-) 136 pub fn string_value(self) -> Option<&'a SmolStr> {
137 pub fn as_cfg(&self) -> Option<&Subtree> { 137 self.attrs().find_map(|attr| match attr.input.as_ref()? {
138 if !self.is_simple_atom("cfg") { 138 AttrInput::Literal(it) => Some(it),
139 return None;
140 }
141 match &self.input {
142 Some(AttrInput::TokenTree(subtree)) => Some(subtree),
143 _ => None, 139 _ => None,
144 } 140 })
145 } 141 }
146 142
147 pub fn as_path(&self) -> Option<&SmolStr> { 143 pub fn exists(self) -> bool {
148 if !self.is_simple_atom("path") { 144 self.attrs().next().is_some()
149 return None;
150 }
151 match &self.input {
152 Some(AttrInput::Literal(it)) => Some(it),
153 _ => None,
154 }
155 } 145 }
156 146
157 pub fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> Option<bool> { 147 fn attrs(self) -> impl Iterator<Item = &'a Attr> {
158 cfg_options.is_cfg_enabled(self.as_cfg()?) 148 let key = self.key;
149 self.attrs
150 .iter()
151 .filter(move |attr| attr.path.as_ident().map_or(false, |s| s.to_string() == key))
159 } 152 }
160} 153}
161 154
@@ -164,8 +157,8 @@ where
164 N: ast::AttrsOwner, 157 N: ast::AttrsOwner,
165 D: DefDatabase, 158 D: DefDatabase,
166{ 159{
167 let hygiene = Hygiene::new(db, src.file_id()); 160 let src = Source::new(src.file_id(), src.to_node(db));
168 Attr::from_attrs_owner(&src.to_node(db), &hygiene) 161 Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner))
169} 162}
170 163
171fn attrs_from_loc<T, D>(node: T, db: &D) -> Attrs 164fn attrs_from_loc<T, D>(node: T, db: &D) -> Attrs
@@ -175,6 +168,5 @@ where
175 D: DefDatabase, 168 D: DefDatabase,
176{ 169{
177 let src = node.source(db); 170 let src = node.source(db);
178 let hygiene = Hygiene::new(db, src.file_id); 171 Attrs::from_attrs_owner(db, src.as_ref().map(|it| it as &dyn AttrsOwner))
179 Attr::from_attrs_owner(&src.value, &hygiene)
180} 172}
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index 225638b42..c06997cf1 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -17,7 +17,7 @@ use crate::{
17 expr::{Expr, ExprId, Pat, PatId}, 17 expr::{Expr, ExprId, Pat, PatId},
18 nameres::CrateDefMap, 18 nameres::CrateDefMap,
19 path::Path, 19 path::Path,
20 AstItemDef, DefWithBodyId, HasModule, HasSource, Lookup, ModuleId, 20 DefWithBodyId, HasModule, HasSource, Lookup, ModuleId,
21}; 21};
22 22
23pub struct Expander { 23pub struct Expander {
@@ -82,7 +82,7 @@ impl Expander {
82 } 82 }
83 83
84 fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> { 84 fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> {
85 self.crate_def_map.resolve_path(db, self.module.module_id, path).0.get_macros() 85 self.crate_def_map.resolve_path(db, self.module.module_id, path).0.take_macros()
86 } 86 }
87} 87}
88 88
@@ -160,6 +160,7 @@ impl Body {
160 (src.file_id, c.module(db), src.value.body()) 160 (src.file_id, c.module(db), src.value.body())
161 } 161 }
162 DefWithBodyId::StaticId(s) => { 162 DefWithBodyId::StaticId(s) => {
163 let s = s.lookup(db);
163 let src = s.source(db); 164 let src = s.source(db);
164 (src.file_id, s.module(db), src.value.body()) 165 (src.file_id, s.module(db), src.value.body())
165 } 166 }
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs
index f0b3e198a..68bea34df 100644
--- a/crates/ra_hir_def/src/data.rs
+++ b/crates/ra_hir_def/src/data.rs
@@ -200,18 +200,17 @@ pub struct ConstData {
200impl ConstData { 200impl ConstData {
201 pub(crate) fn const_data_query(db: &impl DefDatabase, konst: ConstId) -> Arc<ConstData> { 201 pub(crate) fn const_data_query(db: &impl DefDatabase, konst: ConstId) -> Arc<ConstData> {
202 let node = konst.lookup(db).source(db).value; 202 let node = konst.lookup(db).source(db).value;
203 const_data_for(&node) 203 Arc::new(ConstData::new(&node))
204 } 204 }
205 205
206 pub(crate) fn static_data_query(db: &impl DefDatabase, konst: StaticId) -> Arc<ConstData> { 206 pub(crate) fn static_data_query(db: &impl DefDatabase, konst: StaticId) -> Arc<ConstData> {
207 let node = konst.source(db).value; 207 let node = konst.lookup(db).source(db).value;
208 const_data_for(&node) 208 Arc::new(ConstData::new(&node))
209 } 209 }
210}
211 210
212fn const_data_for<N: NameOwner + TypeAscriptionOwner>(node: &N) -> Arc<ConstData> { 211 fn new<N: NameOwner + TypeAscriptionOwner>(node: &N) -> ConstData {
213 let name = node.name().map(|n| n.as_name()); 212 let name = node.name().map(|n| n.as_name());
214 let type_ref = TypeRef::from_ast_opt(node.ascribed_type()); 213 let type_ref = TypeRef::from_ast_opt(node.ascribed_type());
215 let sig = ConstData { name, type_ref }; 214 ConstData { name, type_ref }
216 Arc::new(sig) 215 }
217} 216}
diff --git a/crates/ra_hir_def/src/db.rs b/crates/ra_hir_def/src/db.rs
index 7fec2e8c0..32adb11bd 100644
--- a/crates/ra_hir_def/src/db.rs
+++ b/crates/ra_hir_def/src/db.rs
@@ -18,7 +18,8 @@ use crate::{
18 CrateDefMap, 18 CrateDefMap,
19 }, 19 },
20 AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, FunctionId, FunctionLoc, GenericDefId, 20 AttrDefId, ConstId, ConstLoc, DefWithBodyId, EnumId, FunctionId, FunctionLoc, GenericDefId,
21 ImplId, ItemLoc, ModuleId, StaticId, StructOrUnionId, TraitId, TypeAliasId, TypeAliasLoc, 21 ImplId, ItemLoc, ModuleId, StaticId, StaticLoc, StructOrUnionId, TraitId, TypeAliasId,
22 TypeAliasLoc,
22}; 23};
23 24
24#[salsa::query_group(InternDatabaseStorage)] 25#[salsa::query_group(InternDatabaseStorage)]
@@ -32,7 +33,7 @@ pub trait InternDatabase: SourceDatabase {
32 #[salsa::interned] 33 #[salsa::interned]
33 fn intern_const(&self, loc: ConstLoc) -> ConstId; 34 fn intern_const(&self, loc: ConstLoc) -> ConstId;
34 #[salsa::interned] 35 #[salsa::interned]
35 fn intern_static(&self, loc: ItemLoc<ast::StaticDef>) -> StaticId; 36 fn intern_static(&self, loc: StaticLoc) -> StaticId;
36 #[salsa::interned] 37 #[salsa::interned]
37 fn intern_trait(&self, loc: ItemLoc<ast::TraitDef>) -> TraitId; 38 fn intern_trait(&self, loc: ItemLoc<ast::TraitDef>) -> TraitId;
38 #[salsa::interned] 39 #[salsa::interned]
diff --git a/crates/ra_hir_def/src/docs.rs b/crates/ra_hir_def/src/docs.rs
index 69846fd1b..90a8627bc 100644
--- a/crates/ra_hir_def/src/docs.rs
+++ b/crates/ra_hir_def/src/docs.rs
@@ -1,4 +1,7 @@
1//! FIXME: write short doc here 1//! Defines hir documentation.
2//!
3//! This really shouldn't exist, instead, we should deshugar doc comments into attributes, see
4//! https://github.com/rust-analyzer/rust-analyzer/issues/2148#issuecomment-550519102
2 5
3use std::sync::Arc; 6use std::sync::Arc;
4 7
@@ -52,10 +55,10 @@ impl Documentation {
52 let src = it.parent.child_source(db); 55 let src = it.parent.child_source(db);
53 docs_from_ast(&src.value[it.local_id]) 56 docs_from_ast(&src.value[it.local_id])
54 } 57 }
55 AttrDefId::StaticId(it) => docs_from_ast(&it.source(db).value),
56 AttrDefId::TraitId(it) => docs_from_ast(&it.source(db).value), 58 AttrDefId::TraitId(it) => docs_from_ast(&it.source(db).value),
57 AttrDefId::MacroDefId(it) => docs_from_ast(&it.ast_id.to_node(db)), 59 AttrDefId::MacroDefId(it) => docs_from_ast(&it.ast_id.to_node(db)),
58 AttrDefId::ConstId(it) => docs_from_ast(&it.lookup(db).source(db).value), 60 AttrDefId::ConstId(it) => docs_from_ast(&it.lookup(db).source(db).value),
61 AttrDefId::StaticId(it) => docs_from_ast(&it.lookup(db).source(db).value),
59 AttrDefId::FunctionId(it) => docs_from_ast(&it.lookup(db).source(db).value), 62 AttrDefId::FunctionId(it) => docs_from_ast(&it.lookup(db).source(db).value),
60 AttrDefId::TypeAliasId(it) => docs_from_ast(&it.lookup(db).source(db).value), 63 AttrDefId::TypeAliasId(it) => docs_from_ast(&it.lookup(db).source(db).value),
61 AttrDefId::ImplId(_) => None, 64 AttrDefId::ImplId(_) => None,
diff --git a/crates/ra_hir_def/src/lang_item.rs b/crates/ra_hir_def/src/lang_item.rs
index df951c533..3b9fb0328 100644
--- a/crates/ra_hir_def/src/lang_item.rs
+++ b/crates/ra_hir_def/src/lang_item.rs
@@ -113,8 +113,8 @@ impl LangItems {
113 T: Into<AttrDefId> + Copy, 113 T: Into<AttrDefId> + Copy,
114 { 114 {
115 let attrs = db.attrs(item.into()); 115 let attrs = db.attrs(item.into());
116 if let Some(lang_item_name) = attrs.find_string_value("lang") { 116 if let Some(lang_item_name) = attrs.by_key("lang").string_value() {
117 self.items.entry(lang_item_name).or_insert_with(|| constructor(item)); 117 self.items.entry(lang_item_name.clone()).or_insert_with(|| constructor(item));
118 } 118 }
119 } 119 }
120} 120}
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 1d195d65d..f63c3dd64 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -8,20 +8,23 @@
8//! actually true. 8//! actually true.
9 9
10pub mod db; 10pub mod db;
11
11pub mod attr; 12pub mod attr;
12pub mod path; 13pub mod path;
13pub mod type_ref; 14pub mod type_ref;
14pub mod builtin_type; 15pub mod builtin_type;
15pub mod adt;
16pub mod diagnostics; 16pub mod diagnostics;
17pub mod expr; 17pub mod per_ns;
18pub mod body; 18
19pub mod generics; 19pub mod adt;
20pub mod resolver;
21pub mod data; 20pub mod data;
21pub mod generics;
22pub mod lang_item; 22pub mod lang_item;
23pub mod docs; 23pub mod docs;
24pub mod per_ns; 24
25pub mod expr;
26pub mod body;
27pub mod resolver;
25 28
26mod trace; 29mod trace;
27mod nameres; 30mod nameres;
@@ -35,7 +38,7 @@ use std::hash::{Hash, Hasher};
35 38
36use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, MacroDefId, Source}; 39use hir_expand::{ast_id_map::FileAstId, db::AstDatabase, AstId, HirFileId, MacroDefId, Source};
37use ra_arena::{impl_arena_id, map::ArenaMap, RawId}; 40use ra_arena::{impl_arena_id, map::ArenaMap, RawId};
38use ra_db::{salsa, CrateId}; 41use ra_db::{impl_intern_key, salsa, CrateId};
39use ra_syntax::{ast, AstNode}; 42use ra_syntax::{ast, AstNode};
40 43
41use crate::{builtin_type::BuiltinType, db::InternDatabase}; 44use crate::{builtin_type::BuiltinType, db::InternDatabase};
@@ -56,19 +59,6 @@ pub struct ModuleId {
56pub struct LocalModuleId(RawId); 59pub struct LocalModuleId(RawId);
57impl_arena_id!(LocalModuleId); 60impl_arena_id!(LocalModuleId);
58 61
59macro_rules! impl_intern_key {
60 ($name:ident) => {
61 impl salsa::InternKey for $name {
62 fn from_intern_id(v: salsa::InternId) -> Self {
63 $name(v)
64 }
65 fn as_intern_id(&self) -> salsa::InternId {
66 self.0
67 }
68 }
69 };
70}
71
72#[derive(Debug)] 62#[derive(Debug)]
73pub struct ItemLoc<N: AstNode> { 63pub struct ItemLoc<N: AstNode> {
74 pub(crate) module: ModuleId, 64 pub(crate) module: ModuleId,
@@ -107,25 +97,10 @@ impl<'a, DB> LocationCtx<&'a DB> {
107 } 97 }
108} 98}
109 99
110impl<'a, DB: AstDatabase + InternDatabase> LocationCtx<&'a DB> {
111 pub fn to_def<N, DEF>(self, ast: &N) -> DEF
112 where
113 N: AstNode,
114 DEF: AstItemDef<N>,
115 {
116 DEF::from_ast(self, ast)
117 }
118}
119
120pub trait AstItemDef<N: AstNode>: salsa::InternKey + Clone { 100pub trait AstItemDef<N: AstNode>: salsa::InternKey + Clone {
121 fn intern(db: &impl InternDatabase, loc: ItemLoc<N>) -> Self; 101 fn intern(db: &impl InternDatabase, loc: ItemLoc<N>) -> Self;
122 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<N>; 102 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<N>;
123 103
124 fn from_ast(ctx: LocationCtx<&(impl AstDatabase + InternDatabase)>, ast: &N) -> Self {
125 let items = ctx.db.ast_id_map(ctx.file_id);
126 let item_id = items.ast_id(ast);
127 Self::from_ast_id(ctx, item_id)
128 }
129 fn from_ast_id(ctx: LocationCtx<&impl InternDatabase>, ast_id: FileAstId<N>) -> Self { 104 fn from_ast_id(ctx: LocationCtx<&impl InternDatabase>, ast_id: FileAstId<N>) -> Self {
130 let loc = ItemLoc { module: ctx.module, ast_id: AstId::new(ctx.file_id, ast_id) }; 105 let loc = ItemLoc { module: ctx.module, ast_id: AstId::new(ctx.file_id, ast_id) };
131 Self::intern(ctx.db, loc) 106 Self::intern(ctx.db, loc)
@@ -258,12 +233,24 @@ impl Lookup for ConstId {
258#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 233#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
259pub struct StaticId(salsa::InternId); 234pub struct StaticId(salsa::InternId);
260impl_intern_key!(StaticId); 235impl_intern_key!(StaticId);
261impl AstItemDef<ast::StaticDef> for StaticId { 236
262 fn intern(db: &impl InternDatabase, loc: ItemLoc<ast::StaticDef>) -> Self { 237#[derive(Debug, Clone, PartialEq, Eq, Hash)]
263 db.intern_static(loc) 238pub struct StaticLoc {
239 pub container: ModuleId,
240 pub ast_id: AstId<ast::StaticDef>,
241}
242
243impl Intern for StaticLoc {
244 type ID = StaticId;
245 fn intern(self, db: &impl db::DefDatabase) -> StaticId {
246 db.intern_static(self)
264 } 247 }
265 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<ast::StaticDef> { 248}
266 db.lookup_intern_static(self) 249
250impl Lookup for StaticId {
251 type Data = StaticLoc;
252 fn lookup(&self, db: &impl db::DefDatabase) -> StaticLoc {
253 db.lookup_intern_static(*self)
267 } 254 }
268} 255}
269 256
@@ -494,6 +481,12 @@ impl HasModule for ConstLoc {
494 } 481 }
495} 482}
496 483
484impl HasModule for StaticLoc {
485 fn module(&self, _db: &impl db::DefDatabase) -> ModuleId {
486 self.container
487 }
488}
489
497pub trait HasSource { 490pub trait HasSource {
498 type Value; 491 type Value;
499 fn source(&self, db: &impl db::DefDatabase) -> Source<Self::Value>; 492 fn source(&self, db: &impl db::DefDatabase) -> Source<Self::Value>;
@@ -526,6 +519,15 @@ impl HasSource for ConstLoc {
526 } 519 }
527} 520}
528 521
522impl HasSource for StaticLoc {
523 type Value = ast::StaticDef;
524
525 fn source(&self, db: &impl db::DefDatabase) -> Source<ast::StaticDef> {
526 let node = self.ast_id.to_node(db);
527 Source::new(self.ast_id.file_id(), node)
528 }
529}
530
529pub trait HasChildSource { 531pub trait HasChildSource {
530 type ChildId; 532 type ChildId;
531 type Value; 533 type Value;
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index 3b2e99647..5919771b0 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -66,7 +66,7 @@ use ra_arena::Arena;
66use ra_db::{CrateId, Edition, FileId}; 66use ra_db::{CrateId, Edition, FileId};
67use ra_prof::profile; 67use ra_prof::profile;
68use ra_syntax::ast; 68use ra_syntax::ast;
69use rustc_hash::{FxHashMap, FxHashSet}; 69use rustc_hash::FxHashMap;
70 70
71use crate::{ 71use crate::{
72 builtin_type::BuiltinType, 72 builtin_type::BuiltinType,
@@ -90,18 +90,6 @@ pub struct CrateDefMap {
90 root: LocalModuleId, 90 root: LocalModuleId,
91 modules: Arena<LocalModuleId, ModuleData>, 91 modules: Arena<LocalModuleId, ModuleData>,
92 92
93 /// Some macros are not well-behavior, which leads to infinite loop
94 /// e.g. macro_rules! foo { ($ty:ty) => { foo!($ty); } }
95 /// We mark it down and skip it in collector
96 ///
97 /// FIXME:
98 /// Right now it only handle a poison macro in a single crate,
99 /// such that if other crate try to call that macro,
100 /// the whole process will do again until it became poisoned in that crate.
101 /// We should handle this macro set globally
102 /// However, do we want to put it as a global variable?
103 poison_macros: FxHashSet<MacroDefId>,
104
105 diagnostics: Vec<DefDiagnostic>, 93 diagnostics: Vec<DefDiagnostic>,
106} 94}
107 95
@@ -181,7 +169,7 @@ impl ModuleScope {
181 pub fn macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, MacroDefId)> + 'a { 169 pub fn macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, MacroDefId)> + 'a {
182 self.items 170 self.items
183 .iter() 171 .iter()
184 .filter_map(|(name, res)| res.def.get_macros().map(|macro_| (name, macro_))) 172 .filter_map(|(name, res)| res.def.take_macros().map(|macro_| (name, macro_)))
185 } 173 }
186 174
187 /// Iterate over all legacy textual scoped macros visable at the end of the module 175 /// Iterate over all legacy textual scoped macros visable at the end of the module
@@ -234,7 +222,6 @@ impl CrateDefMap {
234 prelude: None, 222 prelude: None,
235 root, 223 root,
236 modules, 224 modules,
237 poison_macros: FxHashSet::default(),
238 diagnostics: Vec::new(), 225 diagnostics: Vec::new(),
239 } 226 }
240 }; 227 };
@@ -267,16 +254,6 @@ impl CrateDefMap {
267 self.diagnostics.iter().for_each(|it| it.add_to(db, module, sink)) 254 self.diagnostics.iter().for_each(|it| it.add_to(db, module, sink))
268 } 255 }
269 256
270 pub fn resolve_path(
271 &self,
272 db: &impl DefDatabase,
273 original_module: LocalModuleId,
274 path: &Path,
275 ) -> (PerNs, Option<usize>) {
276 let res = self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path);
277 (res.resolved_def, res.segment_index)
278 }
279
280 pub fn modules(&self) -> impl Iterator<Item = LocalModuleId> + '_ { 257 pub fn modules(&self) -> impl Iterator<Item = LocalModuleId> + '_ {
281 self.modules.iter().map(|(id, _data)| id) 258 self.modules.iter().map(|(id, _data)| id)
282 } 259 }
@@ -287,6 +264,16 @@ impl CrateDefMap {
287 .filter(move |(_id, data)| data.definition == Some(file_id)) 264 .filter(move |(_id, data)| data.definition == Some(file_id))
288 .map(|(id, _data)| id) 265 .map(|(id, _data)| id)
289 } 266 }
267
268 pub(crate) fn resolve_path(
269 &self,
270 db: &impl DefDatabase,
271 original_module: LocalModuleId,
272 path: &Path,
273 ) -> (PerNs, Option<usize>) {
274 let res = self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path);
275 (res.resolved_def, res.segment_index)
276 }
290} 277}
291 278
292impl ModuleData { 279impl ModuleData {
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index b02364e86..df01a20e1 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -7,8 +7,8 @@ use hir_expand::{
7}; 7};
8use ra_cfg::CfgOptions; 8use ra_cfg::CfgOptions;
9use ra_db::{CrateId, FileId}; 9use ra_db::{CrateId, FileId};
10use ra_syntax::{ast, SmolStr}; 10use ra_syntax::ast;
11use rustc_hash::FxHashMap; 11use rustc_hash::{FxHashMap, FxHashSet};
12use test_utils::tested_by; 12use test_utils::tested_by;
13 13
14use crate::{ 14use crate::{
@@ -21,7 +21,7 @@ use crate::{
21 path::{Path, PathKind}, 21 path::{Path, PathKind},
22 per_ns::PerNs, 22 per_ns::PerNs,
23 AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplId, 23 AdtId, AstId, AstItemDef, ConstLoc, ContainerId, EnumId, EnumVariantId, FunctionLoc, ImplId,
24 Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticId, StructId, 24 Intern, LocalImportId, LocalModuleId, LocationCtx, ModuleDefId, ModuleId, StaticLoc, StructId,
25 StructOrUnionId, TraitId, TypeAliasLoc, UnionId, 25 StructOrUnionId, TraitId, TypeAliasLoc, UnionId,
26}; 26};
27 27
@@ -57,6 +57,7 @@ pub(super) fn collect_defs(db: &impl DefDatabase, mut def_map: CrateDefMap) -> C
57 unexpanded_macros: Vec::new(), 57 unexpanded_macros: Vec::new(),
58 mod_dirs: FxHashMap::default(), 58 mod_dirs: FxHashMap::default(),
59 macro_stack_monitor: MacroStackMonitor::default(), 59 macro_stack_monitor: MacroStackMonitor::default(),
60 poison_macros: FxHashSet::default(),
60 cfg_options, 61 cfg_options,
61 }; 62 };
62 collector.collect(); 63 collector.collect();
@@ -103,6 +104,17 @@ struct DefCollector<'a, DB> {
103 /// Some macro use `$tt:tt which mean we have to handle the macro perfectly 104 /// Some macro use `$tt:tt which mean we have to handle the macro perfectly
104 /// To prevent stack overflow, we add a deep counter here for prevent that. 105 /// To prevent stack overflow, we add a deep counter here for prevent that.
105 macro_stack_monitor: MacroStackMonitor, 106 macro_stack_monitor: MacroStackMonitor,
107 /// Some macros are not well-behavior, which leads to infinite loop
108 /// e.g. macro_rules! foo { ($ty:ty) => { foo!($ty); } }
109 /// We mark it down and skip it in collector
110 ///
111 /// FIXME:
112 /// Right now it only handle a poison macro in a single crate,
113 /// such that if other crate try to call that macro,
114 /// the whole process will do again until it became poisoned in that crate.
115 /// We should handle this macro set globally
116 /// However, do we want to put it as a global variable?
117 poison_macros: FxHashSet<MacroDefId>,
106 118
107 cfg_options: &'a CfgOptions, 119 cfg_options: &'a CfgOptions,
108} 120}
@@ -464,7 +476,7 @@ where
464 path, 476 path,
465 ); 477 );
466 478
467 if let Some(def) = resolved_res.resolved_def.get_macros() { 479 if let Some(def) = resolved_res.resolved_def.take_macros() {
468 let call_id = self.db.intern_macro(MacroCallLoc { def, ast_id: *ast_id }); 480 let call_id = self.db.intern_macro(MacroCallLoc { def, ast_id: *ast_id });
469 resolved.push((*module_id, call_id, def)); 481 resolved.push((*module_id, call_id, def));
470 res = ReachedFixedPoint::No; 482 res = ReachedFixedPoint::No;
@@ -489,7 +501,7 @@ where
489 macro_call_id: MacroCallId, 501 macro_call_id: MacroCallId,
490 macro_def_id: MacroDefId, 502 macro_def_id: MacroDefId,
491 ) { 503 ) {
492 if self.def_map.poison_macros.contains(&macro_def_id) { 504 if self.poison_macros.contains(&macro_def_id) {
493 return; 505 return;
494 } 506 }
495 507
@@ -509,7 +521,7 @@ where
509 .collect(raw_items.items()); 521 .collect(raw_items.items());
510 } else { 522 } else {
511 log::error!("Too deep macro expansion: {:?}", macro_call_id); 523 log::error!("Too deep macro expansion: {:?}", macro_call_id);
512 self.def_map.poison_macros.insert(macro_def_id); 524 self.poison_macros.insert(macro_def_id);
513 } 525 }
514 526
515 self.macro_stack_monitor.decrease(macro_def_id); 527 self.macro_stack_monitor.decrease(macro_def_id);
@@ -587,8 +599,8 @@ where
587 } 599 }
588 600
589 fn collect_module(&mut self, module: &raw::ModuleData, attrs: &Attrs) { 601 fn collect_module(&mut self, module: &raw::ModuleData, attrs: &Attrs) {
590 let path_attr = self.path_attr(attrs); 602 let path_attr = attrs.by_key("path").string_value();
591 let is_macro_use = attrs.has_atom("macro_use"); 603 let is_macro_use = attrs.by_key("macro_use").exists();
592 match module { 604 match module {
593 // inline module, just recurse 605 // inline module, just recurse
594 raw::ModuleData::Definition { name, items, ast_id } => { 606 raw::ModuleData::Definition { name, items, ast_id } => {
@@ -703,7 +715,10 @@ where
703 PerNs::values(def.into()) 715 PerNs::values(def.into())
704 } 716 }
705 raw::DefKind::Static(ast_id) => { 717 raw::DefKind::Static(ast_id) => {
706 PerNs::values(StaticId::from_ast_id(ctx, ast_id).into()) 718 let def = StaticLoc { container: module, ast_id: AstId::new(self.file_id, ast_id) }
719 .intern(self.def_collector.db);
720
721 PerNs::values(def.into())
707 } 722 }
708 raw::DefKind::Trait(ast_id) => PerNs::types(TraitId::from_ast_id(ctx, ast_id).into()), 723 raw::DefKind::Trait(ast_id) => PerNs::types(TraitId::from_ast_id(ctx, ast_id).into()),
709 raw::DefKind::TypeAlias(ast_id) => { 724 raw::DefKind::TypeAlias(ast_id) => {
@@ -781,11 +796,11 @@ where
781 } 796 }
782 797
783 fn is_cfg_enabled(&self, attrs: &Attrs) -> bool { 798 fn is_cfg_enabled(&self, attrs: &Attrs) -> bool {
784 attrs.iter().all(|attr| attr.is_cfg_enabled(&self.def_collector.cfg_options) != Some(false)) 799 // FIXME: handle cfg_attr :-)
785 } 800 attrs
786 801 .by_key("cfg")
787 fn path_attr<'a>(&self, attrs: &'a Attrs) -> Option<&'a SmolStr> { 802 .tt_values()
788 attrs.iter().find_map(|attr| attr.as_path()) 803 .all(|tt| self.def_collector.cfg_options.is_cfg_enabled(tt) != Some(false))
789 } 804 }
790} 805}
791 806
@@ -807,7 +822,7 @@ mod tests {
807 db: &impl DefDatabase, 822 db: &impl DefDatabase,
808 def_map: CrateDefMap, 823 def_map: CrateDefMap,
809 monitor: MacroStackMonitor, 824 monitor: MacroStackMonitor,
810 ) -> CrateDefMap { 825 ) -> (CrateDefMap, FxHashSet<MacroDefId>) {
811 let mut collector = DefCollector { 826 let mut collector = DefCollector {
812 db, 827 db,
813 def_map, 828 def_map,
@@ -816,13 +831,18 @@ mod tests {
816 unexpanded_macros: Vec::new(), 831 unexpanded_macros: Vec::new(),
817 mod_dirs: FxHashMap::default(), 832 mod_dirs: FxHashMap::default(),
818 macro_stack_monitor: monitor, 833 macro_stack_monitor: monitor,
834 poison_macros: FxHashSet::default(),
819 cfg_options: &CfgOptions::default(), 835 cfg_options: &CfgOptions::default(),
820 }; 836 };
821 collector.collect(); 837 collector.collect();
822 collector.finish() 838 (collector.def_map, collector.poison_macros)
823 } 839 }
824 840
825 fn do_limited_resolve(code: &str, limit: u32, poison_limit: u32) -> CrateDefMap { 841 fn do_limited_resolve(
842 code: &str,
843 limit: u32,
844 poison_limit: u32,
845 ) -> (CrateDefMap, FxHashSet<MacroDefId>) {
826 let (db, _file_id) = TestDB::with_single_file(&code); 846 let (db, _file_id) = TestDB::with_single_file(&code);
827 let krate = db.test_crate(); 847 let krate = db.test_crate();
828 848
@@ -837,7 +857,6 @@ mod tests {
837 prelude: None, 857 prelude: None,
838 root, 858 root,
839 modules, 859 modules,
840 poison_macros: FxHashSet::default(),
841 diagnostics: Vec::new(), 860 diagnostics: Vec::new(),
842 } 861 }
843 }; 862 };
@@ -867,7 +886,7 @@ foo!(KABOOM);
867 886
868 #[test] 887 #[test]
869 fn test_macro_expand_poisoned() { 888 fn test_macro_expand_poisoned() {
870 let def = do_limited_resolve( 889 let (_, poison_macros) = do_limited_resolve(
871 r#" 890 r#"
872 macro_rules! foo { 891 macro_rules! foo {
873 ($ty:ty) => { foo!($ty); } 892 ($ty:ty) => { foo!($ty); }
@@ -878,12 +897,12 @@ foo!(KABOOM);
878 16, 897 16,
879 ); 898 );
880 899
881 assert_eq!(def.poison_macros.len(), 1); 900 assert_eq!(poison_macros.len(), 1);
882 } 901 }
883 902
884 #[test] 903 #[test]
885 fn test_macro_expand_normal() { 904 fn test_macro_expand_normal() {
886 let def = do_limited_resolve( 905 let (_, poison_macros) = do_limited_resolve(
887 r#" 906 r#"
888 macro_rules! foo { 907 macro_rules! foo {
889 ($ident:ident) => { struct $ident {} } 908 ($ident:ident) => { struct $ident {} }
@@ -894,6 +913,6 @@ foo!(Bar);
894 16, 913 16,
895 ); 914 );
896 915
897 assert_eq!(def.poison_macros.len(), 0); 916 assert_eq!(poison_macros.len(), 0);
898 } 917 }
899} 918}
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs
index 552cbe544..2ec84f2cc 100644
--- a/crates/ra_hir_def/src/nameres/raw.rs
+++ b/crates/ra_hir_def/src/nameres/raw.rs
@@ -1,4 +1,9 @@
1//! FIXME: write short doc here 1//! Lowers syntax tree of a rust file into a raw representation of containing
2//! items, *without* attaching them to a module structure.
3//!
4//! That is, raw items don't have semantics, just as syntax, but, unlike syntax,
5//! they don't change with trivial source code edits, making them a great tool
6//! for building salsa recomputation firewalls.
2 7
3use std::{ops::Index, sync::Arc}; 8use std::{ops::Index, sync::Arc};
4 9
@@ -17,10 +22,7 @@ use ra_syntax::{
17use test_utils::tested_by; 22use test_utils::tested_by;
18 23
19use crate::{ 24use crate::{
20 attr::{Attr, Attrs}, 25 attr::Attrs, db::DefDatabase, path::Path, FileAstId, HirFileId, LocalImportId, Source,
21 db::DefDatabase,
22 path::Path,
23 FileAstId, HirFileId, LocalImportId, Source,
24}; 26};
25 27
26/// `RawItems` is a set of top-level items in a file (except for impls). 28/// `RawItems` is a set of top-level items in a file (except for impls).
@@ -407,6 +409,6 @@ impl RawItemsCollector {
407 } 409 }
408 410
409 fn parse_attrs(&self, item: &impl ast::AttrsOwner) -> Attrs { 411 fn parse_attrs(&self, item: &impl ast::AttrsOwner) -> Attrs {
410 Attr::from_attrs_owner(item, &self.hygiene) 412 Attrs::new(item, &self.hygiene)
411 } 413 }
412} 414}
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs
index 626ebffdc..7b2723d57 100644
--- a/crates/ra_hir_def/src/path.rs
+++ b/crates/ra_hir_def/src/path.rs
@@ -1,4 +1,4 @@
1//! FIXME: write short doc here 1//! A desugared representation of paths like `crate::foo` or `<Type as Trait>::bar`.
2 2
3use std::{iter, sync::Arc}; 3use std::{iter, sync::Arc};
4 4
@@ -66,7 +66,7 @@ pub enum PathKind {
66 66
67impl Path { 67impl Path {
68 /// Calls `cb` with all paths, represented by this use item. 68 /// Calls `cb` with all paths, represented by this use item.
69 pub fn expand_use_item( 69 pub(crate) fn expand_use_item(
70 item_src: Source<ast::UseItem>, 70 item_src: Source<ast::UseItem>,
71 hygiene: &Hygiene, 71 hygiene: &Hygiene,
72 mut cb: impl FnMut(Path, &ast::UseTree, bool, Option<Name>), 72 mut cb: impl FnMut(Path, &ast::UseTree, bool, Option<Name>),
@@ -76,7 +76,10 @@ impl Path {
76 } 76 }
77 } 77 }
78 78
79 pub fn from_simple_segments(kind: PathKind, segments: impl IntoIterator<Item = Name>) -> Path { 79 pub(crate) fn from_simple_segments(
80 kind: PathKind,
81 segments: impl IntoIterator<Item = Name>,
82 ) -> Path {
80 Path { 83 Path {
81 kind, 84 kind,
82 segments: segments 85 segments: segments
@@ -94,7 +97,7 @@ impl Path {
94 97
95 /// Converts an `ast::Path` to `Path`. Works with use trees. 98 /// Converts an `ast::Path` to `Path`. Works with use trees.
96 /// It correctly handles `$crate` based path from macro call. 99 /// It correctly handles `$crate` based path from macro call.
97 pub fn from_src(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path> { 100 pub(crate) fn from_src(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path> {
98 let mut kind = PathKind::Plain; 101 let mut kind = PathKind::Plain;
99 let mut segments = Vec::new(); 102 let mut segments = Vec::new();
100 loop { 103 loop {
@@ -227,7 +230,7 @@ impl Path {
227} 230}
228 231
229impl GenericArgs { 232impl GenericArgs {
230 pub fn from_ast(node: ast::TypeArgList) -> Option<GenericArgs> { 233 pub(crate) fn from_ast(node: ast::TypeArgList) -> Option<GenericArgs> {
231 let mut args = Vec::new(); 234 let mut args = Vec::new();
232 for type_arg in node.type_args() { 235 for type_arg in node.type_args() {
233 let type_ref = TypeRef::from_ast_opt(type_arg.type_ref()); 236 let type_ref = TypeRef::from_ast_opt(type_arg.type_ref());
diff --git a/crates/ra_hir_def/src/per_ns.rs b/crates/ra_hir_def/src/per_ns.rs
index 717ed1ef9..06ef6c9fc 100644
--- a/crates/ra_hir_def/src/per_ns.rs
+++ b/crates/ra_hir_def/src/per_ns.rs
@@ -44,10 +44,6 @@ impl PerNs {
44 self.types.is_none() && self.values.is_none() && self.macros.is_none() 44 self.types.is_none() && self.values.is_none() && self.macros.is_none()
45 } 45 }
46 46
47 pub fn is_all(&self) -> bool {
48 self.types.is_some() && self.values.is_some() && self.macros.is_some()
49 }
50
51 pub fn take_types(self) -> Option<ModuleDefId> { 47 pub fn take_types(self) -> Option<ModuleDefId> {
52 self.types 48 self.types
53 } 49 }
@@ -56,14 +52,10 @@ impl PerNs {
56 self.values 52 self.values
57 } 53 }
58 54
59 pub fn get_macros(&self) -> Option<MacroDefId> { 55 pub fn take_macros(self) -> Option<MacroDefId> {
60 self.macros 56 self.macros
61 } 57 }
62 58
63 pub fn only_macros(&self) -> PerNs {
64 PerNs { types: None, values: None, macros: self.macros }
65 }
66
67 pub fn or(self, other: PerNs) -> PerNs { 59 pub fn or(self, other: PerNs) -> PerNs {
68 PerNs { 60 PerNs {
69 types: self.types.or(other.types), 61 types: self.types.or(other.types),
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs
index b56de44dd..7182b8a4d 100644
--- a/crates/ra_hir_def/src/resolver.rs
+++ b/crates/ra_hir_def/src/resolver.rs
@@ -308,7 +308,7 @@ impl Resolver {
308 308
309 pub fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> { 309 pub fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> {
310 let (item_map, module) = self.module()?; 310 let (item_map, module) = self.module()?;
311 item_map.resolve_path(db, module, path).0.get_macros() 311 item_map.resolve_path(db, module, path).0.take_macros()
312 } 312 }
313 313
314 pub fn process_all_names(&self, db: &impl DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) { 314 pub fn process_all_names(&self, db: &impl DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) {
@@ -540,7 +540,7 @@ impl HasResolver for ConstId {
540 540
541impl HasResolver for StaticId { 541impl HasResolver for StaticId {
542 fn resolver(self, db: &impl DefDatabase) -> Resolver { 542 fn resolver(self, db: &impl DefDatabase) -> Resolver {
543 self.module(db).resolver(db) 543 self.lookup(db).container.resolver(db)
544 } 544 }
545} 545}
546 546
diff --git a/crates/ra_hir_def/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs
index 8af061116..5f10e9a88 100644
--- a/crates/ra_hir_def/src/type_ref.rs
+++ b/crates/ra_hir_def/src/type_ref.rs
@@ -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 fn from_ast(node: ast::TypeRef) -> Self { 67 pub(crate) 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 fn from_ast_opt(node: Option<ast::TypeRef>) -> Self { 116 pub(crate) 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 {
@@ -121,7 +121,7 @@ impl TypeRef {
121 } 121 }
122 } 122 }
123 123
124 pub fn unit() -> TypeRef { 124 pub(crate) fn unit() -> TypeRef {
125 TypeRef::Tuple(Vec::new()) 125 TypeRef::Tuple(Vec::new())
126 } 126 }
127} 127}
@@ -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 fn from_ast(node: ast::TypeBound) -> Self { 138 pub(crate) 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() {