diff options
Diffstat (limited to 'crates/ra_hir_def/src/adt.rs')
-rw-r--r-- | crates/ra_hir_def/src/adt.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index be4b0accb..7c0d93691 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; | |||
4 | 4 | ||
5 | use either::Either; | 5 | use either::Either; |
6 | use hir_expand::{ | 6 | use hir_expand::{ |
7 | hygiene::Hygiene, | ||
8 | name::{AsName, Name}, | 7 | name::{AsName, Name}, |
9 | InFile, | 8 | InFile, |
10 | }; | 9 | }; |
@@ -13,7 +12,7 @@ use ra_prof::profile; | |||
13 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner, VisibilityOwner}; | 12 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner, VisibilityOwner}; |
14 | 13 | ||
15 | use crate::{ | 14 | use crate::{ |
16 | attr::Attrs, db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace, | 15 | body::CfgExpander, db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace, |
17 | type_ref::TypeRef, visibility::RawVisibility, EnumId, HasModule, LocalEnumVariantId, | 16 | type_ref::TypeRef, visibility::RawVisibility, EnumId, HasModule, LocalEnumVariantId, |
18 | LocalStructFieldId, Lookup, ModuleId, StructId, UnionId, VariantId, | 17 | LocalStructFieldId, Lookup, ModuleId, StructId, UnionId, VariantId, |
19 | }; | 18 | }; |
@@ -125,8 +124,9 @@ fn lower_enum( | |||
125 | 124 | ||
126 | impl VariantData { | 125 | impl VariantData { |
127 | fn new(db: &dyn DefDatabase, flavor: InFile<ast::StructKind>, module_id: ModuleId) -> Self { | 126 | fn new(db: &dyn DefDatabase, flavor: InFile<ast::StructKind>, module_id: ModuleId) -> Self { |
127 | let mut expander = CfgExpander::new(db, flavor.file_id, module_id.krate); | ||
128 | let mut trace = Trace::new_for_arena(); | 128 | let mut trace = Trace::new_for_arena(); |
129 | match lower_struct(db, &mut trace, &flavor, module_id) { | 129 | match lower_struct(db, &mut expander, &mut trace, &flavor) { |
130 | StructKind::Tuple => VariantData::Tuple(trace.into_arena()), | 130 | StructKind::Tuple => VariantData::Tuple(trace.into_arena()), |
131 | StructKind::Record => VariantData::Record(trace.into_arena()), | 131 | StructKind::Record => VariantData::Record(trace.into_arena()), |
132 | StructKind::Unit => VariantData::Unit, | 132 | StructKind::Unit => VariantData::Unit, |
@@ -178,8 +178,9 @@ impl HasChildSource for VariantId { | |||
178 | it.lookup(db).container.module(db), | 178 | it.lookup(db).container.module(db), |
179 | ), | 179 | ), |
180 | }; | 180 | }; |
181 | let mut expander = CfgExpander::new(db, src.file_id, module_id.krate); | ||
181 | let mut trace = Trace::new_for_map(); | 182 | let mut trace = Trace::new_for_map(); |
182 | lower_struct(db, &mut trace, &src, module_id); | 183 | lower_struct(db, &mut expander, &mut trace, &src); |
183 | src.with_value(trace.into_map()) | 184 | src.with_value(trace.into_map()) |
184 | } | 185 | } |
185 | } | 186 | } |
@@ -193,16 +194,15 @@ pub enum StructKind { | |||
193 | 194 | ||
194 | fn lower_struct( | 195 | fn lower_struct( |
195 | db: &dyn DefDatabase, | 196 | db: &dyn DefDatabase, |
197 | expander: &mut CfgExpander, | ||
196 | trace: &mut Trace<StructFieldData, Either<ast::TupleFieldDef, ast::RecordFieldDef>>, | 198 | trace: &mut Trace<StructFieldData, Either<ast::TupleFieldDef, ast::RecordFieldDef>>, |
197 | ast: &InFile<ast::StructKind>, | 199 | ast: &InFile<ast::StructKind>, |
198 | module_id: ModuleId, | ||
199 | ) -> StructKind { | 200 | ) -> StructKind { |
200 | let crate_graph = db.crate_graph(); | ||
201 | match &ast.value { | 201 | match &ast.value { |
202 | ast::StructKind::Tuple(fl) => { | 202 | ast::StructKind::Tuple(fl) => { |
203 | for (i, fd) in fl.fields().enumerate() { | 203 | for (i, fd) in fl.fields().enumerate() { |
204 | let attrs = Attrs::new(&fd, &Hygiene::new(db.upcast(), ast.file_id)); | 204 | let attrs = expander.parse_attrs(&fd); |
205 | if !attrs.is_cfg_enabled(&crate_graph[module_id.krate].cfg_options) { | 205 | if !expander.is_cfg_enabled(&attrs) { |
206 | continue; | 206 | continue; |
207 | } | 207 | } |
208 | 208 | ||
@@ -219,8 +219,8 @@ fn lower_struct( | |||
219 | } | 219 | } |
220 | ast::StructKind::Record(fl) => { | 220 | ast::StructKind::Record(fl) => { |
221 | for fd in fl.fields() { | 221 | for fd in fl.fields() { |
222 | let attrs = Attrs::new(&fd, &Hygiene::new(db.upcast(), ast.file_id)); | 222 | let attrs = expander.parse_attrs(&fd); |
223 | if !attrs.is_cfg_enabled(&crate_graph[module_id.krate].cfg_options) { | 223 | if !expander.is_cfg_enabled(&attrs) { |
224 | continue; | 224 | continue; |
225 | } | 225 | } |
226 | 226 | ||