diff options
Diffstat (limited to 'crates/ra_hir_def/src/data.rs')
-rw-r--r-- | crates/ra_hir_def/src/data.rs | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index e793ad874..56a20c5bd 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs | |||
@@ -20,7 +20,7 @@ use crate::{ | |||
20 | type_ref::{Mutability, TypeBound, TypeRef}, | 20 | type_ref::{Mutability, TypeBound, TypeRef}, |
21 | visibility::RawVisibility, | 21 | visibility::RawVisibility, |
22 | AssocContainerId, AssocItemId, ConstId, ConstLoc, Expander, FunctionId, FunctionLoc, HasModule, | 22 | AssocContainerId, AssocItemId, ConstId, ConstLoc, Expander, FunctionId, FunctionLoc, HasModule, |
23 | ImplId, Intern, Lookup, ModuleId, StaticId, TraitId, TypeAliasId, TypeAliasLoc, | 23 | ImplId, Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc, |
24 | }; | 24 | }; |
25 | 25 | ||
26 | #[derive(Debug, Clone, PartialEq, Eq)] | 26 | #[derive(Debug, Clone, PartialEq, Eq)] |
@@ -74,7 +74,7 @@ impl FunctionData { | |||
74 | TypeRef::unit() | 74 | TypeRef::unit() |
75 | }; | 75 | }; |
76 | 76 | ||
77 | let ret_type = if src.value.is_async() { | 77 | let ret_type = if src.value.async_token().is_some() { |
78 | let future_impl = desugar_future_path(ret_type); | 78 | let future_impl = desugar_future_path(ret_type); |
79 | let ty_bound = TypeBound::Path(future_impl); | 79 | let ty_bound = TypeBound::Path(future_impl); |
80 | TypeRef::ImplTrait(vec![ty_bound]) | 80 | TypeRef::ImplTrait(vec![ty_bound]) |
@@ -135,7 +135,7 @@ impl TraitData { | |||
135 | pub(crate) fn trait_data_query(db: &dyn DefDatabase, tr: TraitId) -> Arc<TraitData> { | 135 | pub(crate) fn trait_data_query(db: &dyn DefDatabase, tr: TraitId) -> Arc<TraitData> { |
136 | let src = tr.lookup(db).source(db); | 136 | let src = tr.lookup(db).source(db); |
137 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); | 137 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); |
138 | let auto = src.value.is_auto(); | 138 | let auto = src.value.auto_token().is_some(); |
139 | let ast_id_map = db.ast_id_map(src.file_id); | 139 | let ast_id_map = db.ast_id_map(src.file_id); |
140 | 140 | ||
141 | let container = AssocContainerId::TraitId(tr); | 141 | let container = AssocContainerId::TraitId(tr); |
@@ -212,16 +212,23 @@ impl ImplData { | |||
212 | 212 | ||
213 | let target_trait = src.value.target_trait().map(TypeRef::from_ast); | 213 | let target_trait = src.value.target_trait().map(TypeRef::from_ast); |
214 | let target_type = TypeRef::from_ast_opt(src.value.target_type()); | 214 | let target_type = TypeRef::from_ast_opt(src.value.target_type()); |
215 | let is_negative = src.value.is_negative(); | 215 | let is_negative = src.value.excl_token().is_some(); |
216 | let module_id = impl_loc.container.module(db); | 216 | let module_id = impl_loc.container.module(db); |
217 | 217 | ||
218 | let mut items = Vec::new(); | 218 | let mut items = Vec::new(); |
219 | 219 | ||
220 | if let Some(item_list) = src.value.item_list() { | 220 | if let Some(item_list) = src.value.item_list() { |
221 | items.extend(collect_impl_items(db, item_list.impl_items(), src.file_id, id)); | 221 | let mut expander = Expander::new(db, impl_loc.ast_id.file_id, module_id); |
222 | items.extend(collect_impl_items( | ||
223 | db, | ||
224 | &mut expander, | ||
225 | item_list.impl_items(), | ||
226 | src.file_id, | ||
227 | id, | ||
228 | )); | ||
222 | items.extend(collect_impl_items_in_macros( | 229 | items.extend(collect_impl_items_in_macros( |
223 | db, | 230 | db, |
224 | module_id, | 231 | &mut expander, |
225 | &src.with_value(item_list), | 232 | &src.with_value(item_list), |
226 | id, | 233 | id, |
227 | )); | 234 | )); |
@@ -268,18 +275,17 @@ impl ConstData { | |||
268 | 275 | ||
269 | fn collect_impl_items_in_macros( | 276 | fn collect_impl_items_in_macros( |
270 | db: &dyn DefDatabase, | 277 | db: &dyn DefDatabase, |
271 | module_id: ModuleId, | 278 | expander: &mut Expander, |
272 | impl_def: &InFile<ast::ItemList>, | 279 | impl_def: &InFile<ast::ItemList>, |
273 | id: ImplId, | 280 | id: ImplId, |
274 | ) -> Vec<AssocItemId> { | 281 | ) -> Vec<AssocItemId> { |
275 | let mut expander = Expander::new(db, impl_def.file_id, module_id); | ||
276 | let mut res = Vec::new(); | 282 | let mut res = Vec::new(); |
277 | 283 | ||
278 | // We set a limit to protect against infinite recursion | 284 | // We set a limit to protect against infinite recursion |
279 | let limit = 100; | 285 | let limit = 100; |
280 | 286 | ||
281 | for m in impl_def.value.syntax().children().filter_map(ast::MacroCall::cast) { | 287 | for m in impl_def.value.syntax().children().filter_map(ast::MacroCall::cast) { |
282 | res.extend(collect_impl_items_in_macro(db, &mut expander, m, id, limit)) | 288 | res.extend(collect_impl_items_in_macro(db, expander, m, id, limit)) |
283 | } | 289 | } |
284 | 290 | ||
285 | res | 291 | res |
@@ -300,6 +306,7 @@ fn collect_impl_items_in_macro( | |||
300 | let items: InFile<ast::MacroItems> = expander.to_source(items); | 306 | let items: InFile<ast::MacroItems> = expander.to_source(items); |
301 | let mut res = collect_impl_items( | 307 | let mut res = collect_impl_items( |
302 | db, | 308 | db, |
309 | expander, | ||
303 | items.value.items().filter_map(|it| ImplItem::cast(it.syntax().clone())), | 310 | items.value.items().filter_map(|it| ImplItem::cast(it.syntax().clone())), |
304 | items.file_id, | 311 | items.file_id, |
305 | id, | 312 | id, |
@@ -319,32 +326,26 @@ fn collect_impl_items_in_macro( | |||
319 | 326 | ||
320 | fn collect_impl_items( | 327 | fn collect_impl_items( |
321 | db: &dyn DefDatabase, | 328 | db: &dyn DefDatabase, |
329 | expander: &mut Expander, | ||
322 | impl_items: impl Iterator<Item = ImplItem>, | 330 | impl_items: impl Iterator<Item = ImplItem>, |
323 | file_id: crate::HirFileId, | 331 | file_id: crate::HirFileId, |
324 | id: ImplId, | 332 | id: ImplId, |
325 | ) -> Vec<AssocItemId> { | 333 | ) -> Vec<AssocItemId> { |
326 | let items = db.ast_id_map(file_id); | 334 | let items = db.ast_id_map(file_id); |
327 | let crate_graph = db.crate_graph(); | ||
328 | let module_id = id.lookup(db).container.module(db); | ||
329 | 335 | ||
330 | impl_items | 336 | impl_items |
331 | .filter_map(|item_node| match item_node { | 337 | .filter_map(|item_node| match item_node { |
332 | ast::ImplItem::FnDef(it) => { | 338 | ast::ImplItem::FnDef(it) => { |
339 | let attrs = expander.parse_attrs(&it); | ||
340 | if !expander.is_cfg_enabled(&attrs) { | ||
341 | return None; | ||
342 | } | ||
333 | let def = FunctionLoc { | 343 | let def = FunctionLoc { |
334 | container: AssocContainerId::ImplId(id), | 344 | container: AssocContainerId::ImplId(id), |
335 | ast_id: AstId::new(file_id, items.ast_id(&it)), | 345 | ast_id: AstId::new(file_id, items.ast_id(&it)), |
336 | } | 346 | } |
337 | .intern(db); | 347 | .intern(db); |
338 | 348 | Some(def.into()) | |
339 | if !db | ||
340 | .function_data(def) | ||
341 | .attrs | ||
342 | .is_cfg_enabled(&crate_graph[module_id.krate].cfg_options) | ||
343 | { | ||
344 | None | ||
345 | } else { | ||
346 | Some(def.into()) | ||
347 | } | ||
348 | } | 349 | } |
349 | ast::ImplItem::ConstDef(it) => { | 350 | ast::ImplItem::ConstDef(it) => { |
350 | let def = ConstLoc { | 351 | let def = ConstLoc { |