From b8eb1597c9a950a31b06d5625f2793d5237d756c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Apr 2020 17:17:12 +0200 Subject: Use Expander for cfg handling in structs --- crates/ra_hir_def/src/adt.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'crates/ra_hir_def/src/adt.rs') diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index be4b0accb..2619d106d 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs @@ -4,7 +4,6 @@ use std::sync::Arc; use either::Either; use hir_expand::{ - hygiene::Hygiene, name::{AsName, Name}, InFile, }; @@ -13,7 +12,7 @@ use ra_prof::profile; use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner, VisibilityOwner}; use crate::{ - attr::Attrs, db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace, + body::Expander, db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace, type_ref::TypeRef, visibility::RawVisibility, EnumId, HasModule, LocalEnumVariantId, LocalStructFieldId, Lookup, ModuleId, StructId, UnionId, VariantId, }; @@ -125,8 +124,9 @@ fn lower_enum( impl VariantData { fn new(db: &dyn DefDatabase, flavor: InFile, module_id: ModuleId) -> Self { + let mut expander = Expander::new(db, flavor.file_id, module_id); let mut trace = Trace::new_for_arena(); - match lower_struct(db, &mut trace, &flavor, module_id) { + match lower_struct(db, &mut expander, &mut trace, &flavor) { StructKind::Tuple => VariantData::Tuple(trace.into_arena()), StructKind::Record => VariantData::Record(trace.into_arena()), StructKind::Unit => VariantData::Unit, @@ -178,8 +178,9 @@ impl HasChildSource for VariantId { it.lookup(db).container.module(db), ), }; + let mut expander = Expander::new(db, src.file_id, module_id); let mut trace = Trace::new_for_map(); - lower_struct(db, &mut trace, &src, module_id); + lower_struct(db, &mut expander, &mut trace, &src); src.with_value(trace.into_map()) } } @@ -193,16 +194,15 @@ pub enum StructKind { fn lower_struct( db: &dyn DefDatabase, + expander: &mut Expander, trace: &mut Trace>, ast: &InFile, - module_id: ModuleId, ) -> StructKind { - let crate_graph = db.crate_graph(); match &ast.value { ast::StructKind::Tuple(fl) => { for (i, fd) in fl.fields().enumerate() { - let attrs = Attrs::new(&fd, &Hygiene::new(db.upcast(), ast.file_id)); - if !attrs.is_cfg_enabled(&crate_graph[module_id.krate].cfg_options) { + let attrs = expander.parse_attrs(&fd); + if !expander.check_cfg(&attrs) { continue; } @@ -219,8 +219,8 @@ fn lower_struct( } ast::StructKind::Record(fl) => { for fd in fl.fields() { - let attrs = Attrs::new(&fd, &Hygiene::new(db.upcast(), ast.file_id)); - if !attrs.is_cfg_enabled(&crate_graph[module_id.krate].cfg_options) { + let attrs = expander.parse_attrs(&fd); + if !expander.check_cfg(&attrs) { continue; } -- 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/adt.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_def/src/adt.rs') diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index 2619d106d..c7c3c0bc7 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs @@ -202,7 +202,7 @@ fn lower_struct( ast::StructKind::Tuple(fl) => { for (i, fd) in fl.fields().enumerate() { let attrs = expander.parse_attrs(&fd); - if !expander.check_cfg(&attrs) { + if !expander.is_cfg_enabled(&attrs) { continue; } @@ -220,7 +220,7 @@ fn lower_struct( ast::StructKind::Record(fl) => { for fd in fl.fields() { let attrs = expander.parse_attrs(&fd); - if !expander.check_cfg(&attrs) { + if !expander.is_cfg_enabled(&attrs) { continue; } -- cgit v1.2.3 From 38c67e5c0d4297f45ab2b78a00b59f737796d160 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Apr 2020 17:52:26 +0200 Subject: Avoid cyclic queries in name resolution when processing enums --- crates/ra_hir_def/src/adt.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir_def/src/adt.rs') diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index c7c3c0bc7..7c0d93691 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs @@ -12,7 +12,7 @@ use ra_prof::profile; use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner, VisibilityOwner}; use crate::{ - body::Expander, db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace, + body::CfgExpander, db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace, type_ref::TypeRef, visibility::RawVisibility, EnumId, HasModule, LocalEnumVariantId, LocalStructFieldId, Lookup, ModuleId, StructId, UnionId, VariantId, }; @@ -124,7 +124,7 @@ fn lower_enum( impl VariantData { fn new(db: &dyn DefDatabase, flavor: InFile, module_id: ModuleId) -> Self { - let mut expander = Expander::new(db, flavor.file_id, module_id); + let mut expander = CfgExpander::new(db, flavor.file_id, module_id.krate); let mut trace = Trace::new_for_arena(); match lower_struct(db, &mut expander, &mut trace, &flavor) { StructKind::Tuple => VariantData::Tuple(trace.into_arena()), @@ -178,7 +178,7 @@ impl HasChildSource for VariantId { it.lookup(db).container.module(db), ), }; - let mut expander = Expander::new(db, src.file_id, module_id); + let mut expander = CfgExpander::new(db, src.file_id, module_id.krate); let mut trace = Trace::new_for_map(); lower_struct(db, &mut expander, &mut trace, &src); src.with_value(trace.into_map()) @@ -194,7 +194,7 @@ pub enum StructKind { fn lower_struct( db: &dyn DefDatabase, - expander: &mut Expander, + expander: &mut CfgExpander, trace: &mut Trace>, ast: &InFile, ) -> StructKind { -- cgit v1.2.3