From 2bfb65db93e48d8f9e8ecac0b2ea837c081a4db5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Apr 2020 18:40:43 +0200 Subject: Be consistent about token accesors --- crates/ra_hir_def/src/data.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'crates/ra_hir_def/src/data.rs') diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index 606ec48b0..689bb6c5c 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs @@ -75,7 +75,7 @@ impl FunctionData { TypeRef::unit() }; - let ret_type = if src.value.is_async() { + let ret_type = if src.value.async_kw_token().is_some() { let future_impl = desugar_future_path(ret_type); let ty_bound = TypeBound::Path(future_impl); TypeRef::ImplTrait(vec![ty_bound]) @@ -136,7 +136,7 @@ impl TraitData { pub(crate) fn trait_data_query(db: &dyn DefDatabase, tr: TraitId) -> Arc { let src = tr.lookup(db).source(db); let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); - let auto = src.value.is_auto(); + let auto = src.value.auto_kw_token().is_some(); let ast_id_map = db.ast_id_map(src.file_id); let container = AssocContainerId::TraitId(tr); @@ -213,7 +213,7 @@ impl ImplData { let target_trait = src.value.target_trait().map(TypeRef::from_ast); let target_type = TypeRef::from_ast_opt(src.value.target_type()); - let is_negative = src.value.is_negative(); + let is_negative = src.value.excl_token().is_some(); let module_id = impl_loc.container.module(db); let mut items = Vec::new(); -- cgit v1.2.3 From 30084a56a5731343bd4cec727646a6c55900234f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Apr 2020 23:35:05 +0200 Subject: Simpler acessors for keywords --- crates/ra_hir_def/src/data.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src/data.rs') diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index 419d62c28..b8fbf0ed4 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs @@ -74,7 +74,7 @@ impl FunctionData { TypeRef::unit() }; - let ret_type = if src.value.async_kw_token().is_some() { + let ret_type = if src.value.async_token().is_some() { let future_impl = desugar_future_path(ret_type); let ty_bound = TypeBound::Path(future_impl); TypeRef::ImplTrait(vec![ty_bound]) @@ -135,7 +135,7 @@ impl TraitData { pub(crate) fn trait_data_query(db: &dyn DefDatabase, tr: TraitId) -> Arc { let src = tr.lookup(db).source(db); let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); - let auto = src.value.auto_kw_token().is_some(); + let auto = src.value.auto_token().is_some(); let ast_id_map = db.ast_id_map(src.file_id); let container = AssocContainerId::TraitId(tr); -- cgit v1.2.3 From e9519e103573e22ea0b461c81edd8cfc001e6a50 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Apr 2020 17:09:50 +0200 Subject: Pull Expander up --- crates/ra_hir_def/src/data.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir_def/src/data.rs') diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index b8fbf0ed4..dd0e679e8 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs @@ -20,7 +20,7 @@ use crate::{ type_ref::{Mutability, TypeBound, TypeRef}, visibility::RawVisibility, AssocContainerId, AssocItemId, ConstId, ConstLoc, Expander, FunctionId, FunctionLoc, HasModule, - ImplId, Intern, Lookup, ModuleId, StaticId, TraitId, TypeAliasId, TypeAliasLoc, + ImplId, Intern, Lookup, StaticId, TraitId, TypeAliasId, TypeAliasLoc, }; #[derive(Debug, Clone, PartialEq, Eq)] @@ -218,10 +218,11 @@ impl ImplData { let mut items = Vec::new(); 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_in_macros( db, - module_id, + &mut expander, &src.with_value(item_list), id, )); @@ -268,18 +269,17 @@ impl ConstData { fn collect_impl_items_in_macros( db: &dyn DefDatabase, - module_id: ModuleId, + expander: &mut Expander, impl_def: &InFile, id: ImplId, ) -> Vec { - let mut expander = Expander::new(db, impl_def.file_id, module_id); let mut res = Vec::new(); // We set a limit to protect against infinite recursion let limit = 100; for m in impl_def.value.syntax().children().filter_map(ast::MacroCall::cast) { - res.extend(collect_impl_items_in_macro(db, &mut expander, m, id, limit)) + res.extend(collect_impl_items_in_macro(db, expander, m, id, limit)) } res -- cgit v1.2.3 From ac21100f32be00c2b80982fa6faf31c0bfaf2c5f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Apr 2020 17:12:17 +0200 Subject: Use Expander for cfg handling in impls --- crates/ra_hir_def/src/data.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'crates/ra_hir_def/src/data.rs') 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 { 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 = 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, file_id: crate::HirFileId, id: ImplId, ) -> Vec { 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 { -- cgit v1.2.3 From deb40d52aaa1989402fc01d65da389dc92fb66fa Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Apr 2020 17:20:26 +0200 Subject: Align naming --- crates/ra_hir_def/src/data.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_hir_def/src/data.rs') diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index 446af9d9b..56a20c5bd 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs @@ -337,7 +337,7 @@ fn collect_impl_items( .filter_map(|item_node| match item_node { ast::ImplItem::FnDef(it) => { let attrs = expander.parse_attrs(&it); - if !expander.check_cfg(&attrs) { + if !expander.is_cfg_enabled(&attrs) { return None; } let def = FunctionLoc { -- cgit v1.2.3