From ac21100f32be00c2b80982fa6faf31c0bfaf2c5f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Apr 2020 17:12:17 +0200 Subject: Use Expander for cfg handling in impls --- crates/ra_hir_def/src/data.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index dd0e679e8..446af9d9b 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs @@ -219,7 +219,13 @@ impl ImplData { if let Some(item_list) = src.value.item_list() { let mut expander = Expander::new(db, impl_loc.ast_id.file_id, module_id); - items.extend(collect_impl_items(db, item_list.impl_items(), src.file_id, id)); + items.extend(collect_impl_items( + db, + &mut expander, + item_list.impl_items(), + src.file_id, + id, + )); items.extend(collect_impl_items_in_macros( db, &mut expander, @@ -300,6 +306,7 @@ fn collect_impl_items_in_macro( let items: InFile = expander.to_source(items); let mut res = collect_impl_items( db, + expander, items.value.items().filter_map(|it| ImplItem::cast(it.syntax().clone())), items.file_id, id, @@ -319,32 +326,26 @@ fn collect_impl_items_in_macro( fn collect_impl_items( db: &dyn DefDatabase, + expander: &mut Expander, impl_items: impl Iterator, file_id: crate::HirFileId, id: ImplId, ) -> Vec { let items = db.ast_id_map(file_id); - let crate_graph = db.crate_graph(); - let module_id = id.lookup(db).container.module(db); impl_items .filter_map(|item_node| match item_node { ast::ImplItem::FnDef(it) => { + let attrs = expander.parse_attrs(&it); + if !expander.check_cfg(&attrs) { + return None; + } let def = FunctionLoc { container: AssocContainerId::ImplId(id), ast_id: AstId::new(file_id, items.ast_id(&it)), } .intern(db); - - if !db - .function_data(def) - .attrs - .is_cfg_enabled(&crate_graph[module_id.krate].cfg_options) - { - None - } else { - Some(def.into()) - } + Some(def.into()) } ast::ImplItem::ConstDef(it) => { let def = ConstLoc { -- cgit v1.2.3