diff options
Diffstat (limited to 'crates/ra_hir/src/impl_block.rs')
-rw-r--r-- | crates/ra_hir/src/impl_block.rs | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs index 8cf74ddc7..55dfc393b 100644 --- a/crates/ra_hir/src/impl_block.rs +++ b/crates/ra_hir/src/impl_block.rs | |||
@@ -4,12 +4,14 @@ use rustc_hash::FxHashMap; | |||
4 | use std::sync::Arc; | 4 | use std::sync::Arc; |
5 | 5 | ||
6 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; | 6 | use ra_arena::{impl_arena_id, map::ArenaMap, Arena, RawId}; |
7 | use ra_cfg::CfgOptions; | ||
7 | use ra_syntax::{ | 8 | use ra_syntax::{ |
8 | ast::{self, AstNode}, | 9 | ast::{self, AstNode}, |
9 | AstPtr, | 10 | AstPtr, |
10 | }; | 11 | }; |
11 | 12 | ||
12 | use crate::{ | 13 | use crate::{ |
14 | attr::Attr, | ||
13 | code_model::{Module, ModuleSource}, | 15 | code_model::{Module, ModuleSource}, |
14 | db::{AstDatabase, DefDatabase, HirDatabase}, | 16 | db::{AstDatabase, DefDatabase, HirDatabase}, |
15 | generics::HasGenericParams, | 17 | generics::HasGenericParams, |
@@ -176,6 +178,7 @@ pub struct ModuleImplBlocks { | |||
176 | impl ModuleImplBlocks { | 178 | impl ModuleImplBlocks { |
177 | fn collect( | 179 | fn collect( |
178 | db: &(impl DefDatabase + AstDatabase), | 180 | db: &(impl DefDatabase + AstDatabase), |
181 | cfg_options: &CfgOptions, | ||
179 | module: Module, | 182 | module: Module, |
180 | source_map: &mut ImplSourceMap, | 183 | source_map: &mut ImplSourceMap, |
181 | ) -> Self { | 184 | ) -> Self { |
@@ -188,11 +191,11 @@ impl ModuleImplBlocks { | |||
188 | let src = m.module.definition_source(db); | 191 | let src = m.module.definition_source(db); |
189 | match &src.ast { | 192 | match &src.ast { |
190 | ModuleSource::SourceFile(node) => { | 193 | ModuleSource::SourceFile(node) => { |
191 | m.collect_from_item_owner(db, source_map, node, src.file_id) | 194 | m.collect_from_item_owner(db, cfg_options, source_map, node, src.file_id) |
192 | } | 195 | } |
193 | ModuleSource::Module(node) => { | 196 | ModuleSource::Module(node) => { |
194 | let item_list = node.item_list().expect("inline module should have item list"); | 197 | let item_list = node.item_list().expect("inline module should have item list"); |
195 | m.collect_from_item_owner(db, source_map, &item_list, src.file_id) | 198 | m.collect_from_item_owner(db, cfg_options, source_map, &item_list, src.file_id) |
196 | } | 199 | } |
197 | }; | 200 | }; |
198 | m | 201 | m |
@@ -201,6 +204,7 @@ impl ModuleImplBlocks { | |||
201 | fn collect_from_item_owner( | 204 | fn collect_from_item_owner( |
202 | &mut self, | 205 | &mut self, |
203 | db: &(impl DefDatabase + AstDatabase), | 206 | db: &(impl DefDatabase + AstDatabase), |
207 | cfg_options: &CfgOptions, | ||
204 | source_map: &mut ImplSourceMap, | 208 | source_map: &mut ImplSourceMap, |
205 | owner: &dyn ast::ModuleItemOwner, | 209 | owner: &dyn ast::ModuleItemOwner, |
206 | file_id: HirFileId, | 210 | file_id: HirFileId, |
@@ -208,6 +212,13 @@ impl ModuleImplBlocks { | |||
208 | for item in owner.items_with_macros() { | 212 | for item in owner.items_with_macros() { |
209 | match item { | 213 | match item { |
210 | ast::ItemOrMacro::Item(ast::ModuleItem::ImplBlock(impl_block_ast)) => { | 214 | ast::ItemOrMacro::Item(ast::ModuleItem::ImplBlock(impl_block_ast)) => { |
215 | let attrs = Attr::from_attrs_owner(file_id, &impl_block_ast, db); | ||
216 | if attrs.map_or(false, |attrs| { | ||
217 | attrs.iter().any(|attr| attr.is_cfg_enabled(cfg_options) == Some(false)) | ||
218 | }) { | ||
219 | continue; | ||
220 | } | ||
221 | |||
211 | let impl_block = ImplData::from_ast(db, file_id, self.module, &impl_block_ast); | 222 | let impl_block = ImplData::from_ast(db, file_id, self.module, &impl_block_ast); |
212 | let id = self.impls.alloc(impl_block); | 223 | let id = self.impls.alloc(impl_block); |
213 | for &impl_item in &self.impls[id].items { | 224 | for &impl_item in &self.impls[id].items { |
@@ -218,6 +229,13 @@ impl ModuleImplBlocks { | |||
218 | } | 229 | } |
219 | ast::ItemOrMacro::Item(_) => (), | 230 | ast::ItemOrMacro::Item(_) => (), |
220 | ast::ItemOrMacro::Macro(macro_call) => { | 231 | ast::ItemOrMacro::Macro(macro_call) => { |
232 | let attrs = Attr::from_attrs_owner(file_id, ¯o_call, db); | ||
233 | if attrs.map_or(false, |attrs| { | ||
234 | attrs.iter().any(|attr| attr.is_cfg_enabled(cfg_options) == Some(false)) | ||
235 | }) { | ||
236 | continue; | ||
237 | } | ||
238 | |||
221 | //FIXME: we should really cut down on the boilerplate required to process a macro | 239 | //FIXME: we should really cut down on the boilerplate required to process a macro |
222 | let ast_id = db.ast_id_map(file_id).ast_id(¯o_call).with_file_id(file_id); | 240 | let ast_id = db.ast_id_map(file_id).ast_id(¯o_call).with_file_id(file_id); |
223 | if let Some(path) = macro_call | 241 | if let Some(path) = macro_call |
@@ -231,7 +249,13 @@ impl ModuleImplBlocks { | |||
231 | if let Some(item_list) = | 249 | if let Some(item_list) = |
232 | db.parse_or_expand(file_id).and_then(ast::MacroItems::cast) | 250 | db.parse_or_expand(file_id).and_then(ast::MacroItems::cast) |
233 | { | 251 | { |
234 | self.collect_from_item_owner(db, source_map, &item_list, file_id) | 252 | self.collect_from_item_owner( |
253 | db, | ||
254 | cfg_options, | ||
255 | source_map, | ||
256 | &item_list, | ||
257 | file_id, | ||
258 | ) | ||
235 | } | 259 | } |
236 | } | 260 | } |
237 | } | 261 | } |
@@ -246,8 +270,10 @@ pub(crate) fn impls_in_module_with_source_map_query( | |||
246 | module: Module, | 270 | module: Module, |
247 | ) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>) { | 271 | ) -> (Arc<ModuleImplBlocks>, Arc<ImplSourceMap>) { |
248 | let mut source_map = ImplSourceMap::default(); | 272 | let mut source_map = ImplSourceMap::default(); |
273 | let crate_graph = db.crate_graph(); | ||
274 | let cfg_options = crate_graph.cfg_options(module.krate.crate_id()); | ||
249 | 275 | ||
250 | let result = ModuleImplBlocks::collect(db, module, &mut source_map); | 276 | let result = ModuleImplBlocks::collect(db, cfg_options, module, &mut source_map); |
251 | (Arc::new(result), Arc::new(source_map)) | 277 | (Arc::new(result), Arc::new(source_map)) |
252 | } | 278 | } |
253 | 279 | ||