mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-28 04:45:05 +00:00
Use Expander for cfg handling in impls
This commit is contained in:
parent
e9519e1035
commit
ac21100f32
1 changed files with 14 additions and 13 deletions
|
@ -219,7 +219,13 @@ impl ImplData {
|
||||||
|
|
||||||
if let Some(item_list) = src.value.item_list() {
|
if let Some(item_list) = src.value.item_list() {
|
||||||
let mut expander = Expander::new(db, impl_loc.ast_id.file_id, module_id);
|
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(
|
items.extend(collect_impl_items_in_macros(
|
||||||
db,
|
db,
|
||||||
&mut expander,
|
&mut expander,
|
||||||
|
@ -300,6 +306,7 @@ fn collect_impl_items_in_macro(
|
||||||
let items: InFile<ast::MacroItems> = expander.to_source(items);
|
let items: InFile<ast::MacroItems> = expander.to_source(items);
|
||||||
let mut res = collect_impl_items(
|
let mut res = collect_impl_items(
|
||||||
db,
|
db,
|
||||||
|
expander,
|
||||||
items.value.items().filter_map(|it| ImplItem::cast(it.syntax().clone())),
|
items.value.items().filter_map(|it| ImplItem::cast(it.syntax().clone())),
|
||||||
items.file_id,
|
items.file_id,
|
||||||
id,
|
id,
|
||||||
|
@ -319,32 +326,26 @@ fn collect_impl_items_in_macro(
|
||||||
|
|
||||||
fn collect_impl_items(
|
fn collect_impl_items(
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
|
expander: &mut Expander,
|
||||||
impl_items: impl Iterator<Item = ImplItem>,
|
impl_items: impl Iterator<Item = ImplItem>,
|
||||||
file_id: crate::HirFileId,
|
file_id: crate::HirFileId,
|
||||||
id: ImplId,
|
id: ImplId,
|
||||||
) -> Vec<AssocItemId> {
|
) -> Vec<AssocItemId> {
|
||||||
let items = db.ast_id_map(file_id);
|
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
|
impl_items
|
||||||
.filter_map(|item_node| match item_node {
|
.filter_map(|item_node| match item_node {
|
||||||
ast::ImplItem::FnDef(it) => {
|
ast::ImplItem::FnDef(it) => {
|
||||||
|
let attrs = expander.parse_attrs(&it);
|
||||||
|
if !expander.check_cfg(&attrs) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
let def = FunctionLoc {
|
let def = FunctionLoc {
|
||||||
container: AssocContainerId::ImplId(id),
|
container: AssocContainerId::ImplId(id),
|
||||||
ast_id: AstId::new(file_id, items.ast_id(&it)),
|
ast_id: AstId::new(file_id, items.ast_id(&it)),
|
||||||
}
|
}
|
||||||
.intern(db);
|
.intern(db);
|
||||||
|
Some(def.into())
|
||||||
if !db
|
|
||||||
.function_data(def)
|
|
||||||
.attrs
|
|
||||||
.is_cfg_enabled(&crate_graph[module_id.krate].cfg_options)
|
|
||||||
{
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(def.into())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ast::ImplItem::ConstDef(it) => {
|
ast::ImplItem::ConstDef(it) => {
|
||||||
let def = ConstLoc {
|
let def = ConstLoc {
|
||||||
|
|
Loading…
Reference in a new issue