aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/adt.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/adt.rs')
-rw-r--r--crates/ra_hir_def/src/adt.rs30
1 files changed, 3 insertions, 27 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs
index 8527a6cad..7fc4cd76e 100644
--- a/crates/ra_hir_def/src/adt.rs
+++ b/crates/ra_hir_def/src/adt.rs
@@ -4,19 +4,17 @@ use std::sync::Arc;
4 4
5use either::Either; 5use either::Either;
6use hir_expand::{ 6use hir_expand::{
7 hygiene::Hygiene,
8 name::{AsName, Name}, 7 name::{AsName, Name},
9 InFile, 8 InFile,
10}; 9};
11use ra_arena::{map::ArenaMap, Arena}; 10use ra_arena::{map::ArenaMap, Arena};
12use ra_cfg::CfgOptions;
13use ra_prof::profile; 11use ra_prof::profile;
14use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner, VisibilityOwner}; 12use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner, VisibilityOwner};
15 13
16use crate::{ 14use crate::{
17 attr::Attrs, db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace, 15 db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace, type_ref::TypeRef,
18 type_ref::TypeRef, visibility::RawVisibility, EnumId, LocalEnumVariantId, LocalStructFieldId, 16 visibility::RawVisibility, EnumId, LocalEnumVariantId, LocalStructFieldId, Lookup, StructId,
19 Lookup, StructId, UnionId, VariantId, 17 UnionId, VariantId,
20}; 18};
21 19
22/// Note that we use `StructData` for unions as well! 20/// Note that we use `StructData` for unions as well!
@@ -51,8 +49,6 @@ pub struct StructFieldData {
51 pub name: Name, 49 pub name: Name,
52 pub type_ref: TypeRef, 50 pub type_ref: TypeRef,
53 pub visibility: RawVisibility, 51 pub visibility: RawVisibility,
54 pub attrs: Attrs,
55 // TODO: add attributes
56} 52}
57 53
58impl StructData { 54impl StructData {
@@ -186,10 +182,6 @@ pub enum StructKind {
186 Unit, 182 Unit,
187} 183}
188 184
189fn is_cfg_enabled(cfg_options: &CfgOptions, attrs: &Attrs) -> bool {
190 attrs.by_key("cfg").tt_values().all(|tt| cfg_options.is_cfg_enabled(tt) != Some(false))
191}
192
193fn lower_struct( 185fn lower_struct(
194 db: &dyn DefDatabase, 186 db: &dyn DefDatabase,
195 trace: &mut Trace<StructFieldData, Either<ast::TupleFieldDef, ast::RecordFieldDef>>, 187 trace: &mut Trace<StructFieldData, Either<ast::TupleFieldDef, ast::RecordFieldDef>>,
@@ -198,21 +190,12 @@ fn lower_struct(
198 match &ast.value { 190 match &ast.value {
199 ast::StructKind::Tuple(fl) => { 191 ast::StructKind::Tuple(fl) => {
200 for (i, fd) in fl.fields().enumerate() { 192 for (i, fd) in fl.fields().enumerate() {
201 let attrs = Attrs::new(&fd, &Hygiene::new(db.upcast(), ast.file_id));
202
203 // Need verification about parent cfg_options and current with current attributes
204 // If it is we are in a case where the cfg is not enabled then we don't have to add this field to check
205 // if !is_cfg_enabled(&crate_graph[module_id.krate].cfg_options, &attrs) {
206 // continue;
207 // }
208
209 trace.alloc( 193 trace.alloc(
210 || Either::Left(fd.clone()), 194 || Either::Left(fd.clone()),
211 || StructFieldData { 195 || StructFieldData {
212 name: Name::new_tuple_field(i), 196 name: Name::new_tuple_field(i),
213 type_ref: TypeRef::from_ast_opt(fd.type_ref()), 197 type_ref: TypeRef::from_ast_opt(fd.type_ref()),
214 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())), 198 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())),
215 attrs: Attrs::new(&fd, &Hygiene::new(db.upcast(), ast.file_id)),
216 }, 199 },
217 ); 200 );
218 } 201 }
@@ -220,19 +203,12 @@ fn lower_struct(
220 } 203 }
221 ast::StructKind::Record(fl) => { 204 ast::StructKind::Record(fl) => {
222 for fd in fl.fields() { 205 for fd in fl.fields() {
223 let attrs = Attrs::new(&fd, &Hygiene::new(db.upcast(), ast.file_id));
224 // Need verification about parent cfg_options and current with current attributes
225 // If it is we are in a case where the cfg is not enabled then we don't have to add this field to check
226 // if !is_cfg_enabled(&crate_graph[module_id.krate].cfg_options, &attrs) {
227 // continue;
228 // }
229 trace.alloc( 206 trace.alloc(
230 || Either::Right(fd.clone()), 207 || Either::Right(fd.clone()),
231 || StructFieldData { 208 || StructFieldData {
232 name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing), 209 name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing),
233 type_ref: TypeRef::from_ast_opt(fd.ascribed_type()), 210 type_ref: TypeRef::from_ast_opt(fd.ascribed_type()),
234 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())), 211 visibility: RawVisibility::from_ast(db, ast.with_value(fd.visibility())),
235 attrs: Attrs::new(&fd, &Hygiene::new(db.upcast(), ast.file_id)),
236 }, 212 },
237 ); 213 );
238 } 214 }