diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-04-11 16:55:26 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-04-11 16:55:26 +0100 |
commit | e7a68c8f55e0770fdeae508a1710509c13aaffa1 (patch) | |
tree | 56227291b99e0bdccf2b41c911d797794908d3c4 /crates/ra_hir_def/src/data.rs | |
parent | 997c959d4f373df0cbba09609c5e4d8215d3d0c7 (diff) | |
parent | f980b0752994a1b823499f6edb10fd9c4c285c42 (diff) |
Merge #3949
3949: Cleanup cfg handling in items r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src/data.rs')
-rw-r--r-- | crates/ra_hir_def/src/data.rs | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index b8fbf0ed4..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)] |
@@ -218,10 +218,17 @@ impl ImplData { | |||
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 { |