diff options
author | Florian Diebold <[email protected]> | 2018-12-25 20:40:33 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2018-12-25 20:40:33 +0000 |
commit | bc745a139674f289386f3081458793f756cab5b9 (patch) | |
tree | 518c38ce87807c76644b512ce0213dd01e43614a /crates/ra_hir/src/query_definitions.rs | |
parent | cdca39706121b2d1734a94938a2372da881e10c6 (diff) |
Resolve field types lazily
I.e. not already when getting the HIR for the struct.
Diffstat (limited to 'crates/ra_hir/src/query_definitions.rs')
-rw-r--r-- | crates/ra_hir/src/query_definitions.rs | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index 405e359f1..4a7958a12 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs | |||
@@ -46,18 +46,21 @@ pub(super) fn type_for_def(db: &impl HirDatabase, def_id: DefId) -> Cancelable<T | |||
46 | ty::type_for_def(db, def_id) | 46 | ty::type_for_def(db, def_id) |
47 | } | 47 | } |
48 | 48 | ||
49 | pub(super) fn type_for_field( | ||
50 | db: &impl HirDatabase, | ||
51 | def_id: DefId, | ||
52 | field: SmolStr, | ||
53 | ) -> Cancelable<Ty> { | ||
54 | ty::type_for_field(db, def_id, field) | ||
55 | } | ||
56 | |||
49 | pub(super) fn struct_data(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<StructData>> { | 57 | pub(super) fn struct_data(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<StructData>> { |
50 | let def_loc = def_id.loc(db); | 58 | let def_loc = def_id.loc(db); |
51 | assert!(def_loc.kind == DefKind::Struct); | 59 | assert!(def_loc.kind == DefKind::Struct); |
52 | let syntax = db.file_item(def_loc.source_item_id); | 60 | let syntax = db.file_item(def_loc.source_item_id); |
53 | let struct_def = | 61 | let struct_def = |
54 | ast::StructDef::cast(syntax.borrowed()).expect("struct def should point to StructDef node"); | 62 | ast::StructDef::cast(syntax.borrowed()).expect("struct def should point to StructDef node"); |
55 | let module = def_id.module(db)?; | 63 | Ok(Arc::new(StructData::new(struct_def.borrowed()))) |
56 | Ok(Arc::new(StructData::new( | ||
57 | db, | ||
58 | &module, | ||
59 | struct_def.borrowed(), | ||
60 | )?)) | ||
61 | } | 64 | } |
62 | 65 | ||
63 | pub(super) fn enum_data(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<EnumData>> { | 66 | pub(super) fn enum_data(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<EnumData>> { |
@@ -66,8 +69,7 @@ pub(super) fn enum_data(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc< | |||
66 | let syntax = db.file_item(def_loc.source_item_id); | 69 | let syntax = db.file_item(def_loc.source_item_id); |
67 | let enum_def = | 70 | let enum_def = |
68 | ast::EnumDef::cast(syntax.borrowed()).expect("enum def should point to EnumDef node"); | 71 | ast::EnumDef::cast(syntax.borrowed()).expect("enum def should point to EnumDef node"); |
69 | let module = def_id.module(db)?; | 72 | Ok(Arc::new(EnumData::new(enum_def.borrowed()))) |
70 | Ok(Arc::new(EnumData::new(db, &module, enum_def.borrowed())?)) | ||
71 | } | 73 | } |
72 | 74 | ||
73 | pub(super) fn file_items(db: &impl HirDatabase, file_id: FileId) -> Arc<SourceFileItems> { | 75 | pub(super) fn file_items(db: &impl HirDatabase, file_id: FileId) -> Arc<SourceFileItems> { |