Use Expander for cfg handling in impls
This commit is contained in:
parent
e9519e1035
commit
ac21100f32
@ -219,7 +219,13 @@ pub(crate) fn impl_data_query(db: &dyn DefDatabase, id: ImplId) -> Arc<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<ast::MacroItems> = 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<Item = ImplItem>,
|
||||
file_id: crate::HirFileId,
|
||||
id: ImplId,
|
||||
) -> Vec<AssocItemId> {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user