diff options
author | Aleksey Kladov <[email protected]> | 2020-04-11 16:12:17 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-04-11 16:12:17 +0100 |
commit | ac21100f32be00c2b80982fa6faf31c0bfaf2c5f (patch) | |
tree | 78298e7bf93e851aa9aa17fe97d4dc1f35569287 /crates | |
parent | e9519e103573e22ea0b461c81edd8cfc001e6a50 (diff) |
Use Expander for cfg handling in impls
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_def/src/data.rs | 27 |
1 files changed, 14 insertions, 13 deletions
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 { | |||
219 | 219 | ||
220 | if let Some(item_list) = src.value.item_list() { | 220 | if let Some(item_list) = src.value.item_list() { |
221 | let mut expander = Expander::new(db, impl_loc.ast_id.file_id, module_id); | 221 | let mut expander = Expander::new(db, impl_loc.ast_id.file_id, module_id); |
222 | items.extend(collect_impl_items(db, item_list.impl_items(), src.file_id, id)); | 222 | items.extend(collect_impl_items( |
223 | db, | ||
224 | &mut expander, | ||
225 | item_list.impl_items(), | ||
226 | src.file_id, | ||
227 | id, | ||
228 | )); | ||
223 | items.extend(collect_impl_items_in_macros( | 229 | items.extend(collect_impl_items_in_macros( |
224 | db, | 230 | db, |
225 | &mut expander, | 231 | &mut expander, |
@@ -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.check_cfg(&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 { |