diff options
Diffstat (limited to 'crates/ra_hir/src/adt.rs')
-rw-r--r-- | crates/ra_hir/src/adt.rs | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index bcb705c24..d87fe7049 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs | |||
@@ -1,6 +1,5 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use ra_db::Cancelable; | ||
4 | use ra_syntax::{ | 3 | use ra_syntax::{ |
5 | SyntaxNode, | 4 | SyntaxNode, |
6 | ast::{self, NameOwner, StructFlavor, AstNode} | 5 | ast::{self, NameOwner, StructFlavor, AstNode} |
@@ -18,8 +17,8 @@ impl Struct { | |||
18 | Struct { def_id } | 17 | Struct { def_id } |
19 | } | 18 | } |
20 | 19 | ||
21 | pub(crate) fn variant_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<VariantData>> { | 20 | pub(crate) fn variant_data(&self, db: &impl HirDatabase) -> Arc<VariantData> { |
22 | Ok(db.struct_data(self.def_id)?.variant_data.clone()) | 21 | db.struct_data(self.def_id).variant_data.clone() |
23 | } | 22 | } |
24 | } | 23 | } |
25 | 24 | ||
@@ -37,16 +36,13 @@ impl StructData { | |||
37 | StructData { name, variant_data } | 36 | StructData { name, variant_data } |
38 | } | 37 | } |
39 | 38 | ||
40 | pub(crate) fn struct_data_query( | 39 | pub(crate) fn struct_data_query(db: &impl HirDatabase, def_id: DefId) -> Arc<StructData> { |
41 | db: &impl HirDatabase, | ||
42 | def_id: DefId, | ||
43 | ) -> Cancelable<Arc<StructData>> { | ||
44 | let def_loc = def_id.loc(db); | 40 | let def_loc = def_id.loc(db); |
45 | assert!(def_loc.kind == DefKind::Struct); | 41 | assert!(def_loc.kind == DefKind::Struct); |
46 | let syntax = db.file_item(def_loc.source_item_id); | 42 | let syntax = db.file_item(def_loc.source_item_id); |
47 | let struct_def = | 43 | let struct_def = |
48 | ast::StructDef::cast(&syntax).expect("struct def should point to StructDef node"); | 44 | ast::StructDef::cast(&syntax).expect("struct def should point to StructDef node"); |
49 | Ok(Arc::new(StructData::new(struct_def))) | 45 | Arc::new(StructData::new(struct_def)) |
50 | } | 46 | } |
51 | } | 47 | } |
52 | 48 | ||
@@ -84,10 +80,7 @@ impl EnumData { | |||
84 | EnumData { name, variants } | 80 | EnumData { name, variants } |
85 | } | 81 | } |
86 | 82 | ||
87 | pub(crate) fn enum_data_query( | 83 | pub(crate) fn enum_data_query(db: &impl HirDatabase, def_id: DefId) -> Arc<EnumData> { |
88 | db: &impl HirDatabase, | ||
89 | def_id: DefId, | ||
90 | ) -> Cancelable<Arc<EnumData>> { | ||
91 | let def_loc = def_id.loc(db); | 84 | let def_loc = def_id.loc(db); |
92 | assert!(def_loc.kind == DefKind::Enum); | 85 | assert!(def_loc.kind == DefKind::Enum); |
93 | let syntax = db.file_item(def_loc.source_item_id); | 86 | let syntax = db.file_item(def_loc.source_item_id); |
@@ -107,7 +100,7 @@ impl EnumData { | |||
107 | } else { | 100 | } else { |
108 | Vec::new() | 101 | Vec::new() |
109 | }; | 102 | }; |
110 | Ok(Arc::new(EnumData::new(enum_def, variants))) | 103 | Arc::new(EnumData::new(enum_def, variants)) |
111 | } | 104 | } |
112 | } | 105 | } |
113 | 106 | ||
@@ -133,7 +126,7 @@ impl EnumVariantData { | |||
133 | pub(crate) fn enum_variant_data_query( | 126 | pub(crate) fn enum_variant_data_query( |
134 | db: &impl HirDatabase, | 127 | db: &impl HirDatabase, |
135 | def_id: DefId, | 128 | def_id: DefId, |
136 | ) -> Cancelable<Arc<EnumVariantData>> { | 129 | ) -> Arc<EnumVariantData> { |
137 | let def_loc = def_id.loc(db); | 130 | let def_loc = def_id.loc(db); |
138 | assert!(def_loc.kind == DefKind::EnumVariant); | 131 | assert!(def_loc.kind == DefKind::EnumVariant); |
139 | let syntax = db.file_item(def_loc.source_item_id); | 132 | let syntax = db.file_item(def_loc.source_item_id); |
@@ -146,10 +139,7 @@ impl EnumVariantData { | |||
146 | .expect("enum variant list should have enum ancestor"); | 139 | .expect("enum variant list should have enum ancestor"); |
147 | let enum_def_id = get_def_id(db, &def_loc, enum_node, DefKind::Enum); | 140 | let enum_def_id = get_def_id(db, &def_loc, enum_node, DefKind::Enum); |
148 | 141 | ||
149 | Ok(Arc::new(EnumVariantData::new( | 142 | Arc::new(EnumVariantData::new(variant_def, Enum::new(enum_def_id))) |
150 | variant_def, | ||
151 | Enum::new(enum_def_id), | ||
152 | ))) | ||
153 | } | 143 | } |
154 | } | 144 | } |
155 | 145 | ||