@@ -4,12 +4,14 @@ use rustc_hash::FxHashMap;
4
4
use std:: sync:: Arc ;
5
5
6
6
use ra_arena:: { impl_arena_id, map:: ArenaMap , Arena , RawId } ;
7
+ use ra_cfg:: CfgOptions ;
7
8
use ra_syntax:: {
8
9
ast:: { self , AstNode } ,
9
10
AstPtr ,
10
11
} ;
11
12
12
13
use crate :: {
14
+ attr:: Attr ,
13
15
code_model:: { Module , ModuleSource } ,
14
16
db:: { AstDatabase , DefDatabase , HirDatabase } ,
15
17
generics:: HasGenericParams ,
@@ -176,6 +178,7 @@ pub struct ModuleImplBlocks {
176
178
impl ModuleImplBlocks {
177
179
fn collect (
178
180
db : & ( impl DefDatabase + AstDatabase ) ,
181
+ cfg_options : & CfgOptions ,
179
182
module : Module ,
180
183
source_map : & mut ImplSourceMap ,
181
184
) -> Self {
@@ -188,11 +191,11 @@ impl ModuleImplBlocks {
188
191
let src = m. module . definition_source ( db) ;
189
192
match & src. ast {
190
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
196
ModuleSource :: Module ( node) => {
194
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
201
m
@@ -201,13 +204,19 @@ impl ModuleImplBlocks {
201
204
fn collect_from_item_owner (
202
205
& mut self ,
203
206
db : & ( impl DefDatabase + AstDatabase ) ,
207
+ cfg_options : & CfgOptions ,
204
208
source_map : & mut ImplSourceMap ,
205
209
owner : & dyn ast:: ModuleItemOwner ,
206
210
file_id : HirFileId ,
207
211
) {
208
212
for item in owner. items_with_macros ( ) {
209
213
match item {
210
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. iter ( ) . any ( |attr| attr. is_cfg_enabled ( cfg_options) == Some ( false ) ) {
217
+ continue ;
218
+ }
219
+
211
220
let impl_block = ImplData :: from_ast ( db, file_id, self . module , & impl_block_ast) ;
212
221
let id = self . impls . alloc ( impl_block) ;
213
222
for & impl_item in & self . impls [ id] . items {
@@ -218,6 +227,11 @@ impl ModuleImplBlocks {
218
227
}
219
228
ast:: ItemOrMacro :: Item ( _) => ( ) ,
220
229
ast:: ItemOrMacro :: Macro ( macro_call) => {
230
+ let attrs = Attr :: from_attrs_owner ( file_id, & macro_call, db) ;
231
+ if attrs. iter ( ) . any ( |attr| attr. is_cfg_enabled ( cfg_options) == Some ( false ) ) {
232
+ continue ;
233
+ }
234
+
221
235
//FIXME: we should really cut down on the boilerplate required to process a macro
222
236
let ast_id = db. ast_id_map ( file_id) . ast_id ( & macro_call) . with_file_id ( file_id) ;
223
237
if let Some ( path) = macro_call
@@ -231,7 +245,13 @@ impl ModuleImplBlocks {
231
245
if let Some ( item_list) =
232
246
db. parse_or_expand ( file_id) . and_then ( ast:: MacroItems :: cast)
233
247
{
234
- self . collect_from_item_owner ( db, source_map, & item_list, file_id)
248
+ self . collect_from_item_owner (
249
+ db,
250
+ cfg_options,
251
+ source_map,
252
+ & item_list,
253
+ file_id,
254
+ )
235
255
}
236
256
}
237
257
}
@@ -246,8 +266,10 @@ pub(crate) fn impls_in_module_with_source_map_query(
246
266
module : Module ,
247
267
) -> ( Arc < ModuleImplBlocks > , Arc < ImplSourceMap > ) {
248
268
let mut source_map = ImplSourceMap :: default ( ) ;
269
+ let crate_graph = db. crate_graph ( ) ;
270
+ let cfg_options = crate_graph. cfg_options ( module. krate . crate_id ( ) ) ;
249
271
250
- let result = ModuleImplBlocks :: collect ( db, module, & mut source_map) ;
272
+ let result = ModuleImplBlocks :: collect ( db, cfg_options , module, & mut source_map) ;
251
273
( Arc :: new ( result) , Arc :: new ( source_map) )
252
274
}
253
275
0 commit comments