aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-15 15:43:25 +0000
committerAleksey Kladov <[email protected]>2019-01-15 15:43:25 +0000
commit9446be29992fe14ec529874622311c3ae7a49b0e (patch)
tree28ed14b3de7239994ba19b304e72c86f8d37de23 /crates/ra_hir
parent05149d353299b54476410daeda6551e1261128ef (diff)
remove Cancelable from adt API
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/adt.rs23
-rw-r--r--crates/ra_hir/src/code_model_api.rs50
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs2
-rw-r--r--crates/ra_hir/src/db.rs6
-rw-r--r--crates/ra_hir/src/ty.rs8
5 files changed, 36 insertions, 53 deletions
diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs
index bcb705c24..57d112f74 100644
--- a/crates/ra_hir/src/adt.rs
+++ b/crates/ra_hir/src/adt.rs
@@ -19,7 +19,7 @@ impl Struct {
19 } 19 }
20 20
21 pub(crate) fn variant_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<VariantData>> { 21 pub(crate) fn variant_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<VariantData>> {
22 Ok(db.struct_data(self.def_id)?.variant_data.clone()) 22 Ok(db.struct_data(self.def_id).variant_data.clone())
23 } 23 }
24} 24}
25 25
@@ -37,16 +37,13 @@ impl StructData {
37 StructData { name, variant_data } 37 StructData { name, variant_data }
38 } 38 }
39 39
40 pub(crate) fn struct_data_query( 40 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); 41 let def_loc = def_id.loc(db);
45 assert!(def_loc.kind == DefKind::Struct); 42 assert!(def_loc.kind == DefKind::Struct);
46 let syntax = db.file_item(def_loc.source_item_id); 43 let syntax = db.file_item(def_loc.source_item_id);
47 let struct_def = 44 let struct_def =
48 ast::StructDef::cast(&syntax).expect("struct def should point to StructDef node"); 45 ast::StructDef::cast(&syntax).expect("struct def should point to StructDef node");
49 Ok(Arc::new(StructData::new(struct_def))) 46 Arc::new(StructData::new(struct_def))
50 } 47 }
51} 48}
52 49
@@ -84,10 +81,7 @@ impl EnumData {
84 EnumData { name, variants } 81 EnumData { name, variants }
85 } 82 }
86 83
87 pub(crate) fn enum_data_query( 84 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); 85 let def_loc = def_id.loc(db);
92 assert!(def_loc.kind == DefKind::Enum); 86 assert!(def_loc.kind == DefKind::Enum);
93 let syntax = db.file_item(def_loc.source_item_id); 87 let syntax = db.file_item(def_loc.source_item_id);
@@ -107,7 +101,7 @@ impl EnumData {
107 } else { 101 } else {
108 Vec::new() 102 Vec::new()
109 }; 103 };
110 Ok(Arc::new(EnumData::new(enum_def, variants))) 104 Arc::new(EnumData::new(enum_def, variants))
111 } 105 }
112} 106}
113 107
@@ -133,7 +127,7 @@ impl EnumVariantData {
133 pub(crate) fn enum_variant_data_query( 127 pub(crate) fn enum_variant_data_query(
134 db: &impl HirDatabase, 128 db: &impl HirDatabase,
135 def_id: DefId, 129 def_id: DefId,
136 ) -> Cancelable<Arc<EnumVariantData>> { 130 ) -> Arc<EnumVariantData> {
137 let def_loc = def_id.loc(db); 131 let def_loc = def_id.loc(db);
138 assert!(def_loc.kind == DefKind::EnumVariant); 132 assert!(def_loc.kind == DefKind::EnumVariant);
139 let syntax = db.file_item(def_loc.source_item_id); 133 let syntax = db.file_item(def_loc.source_item_id);
@@ -146,10 +140,7 @@ impl EnumVariantData {
146 .expect("enum variant list should have enum ancestor"); 140 .expect("enum variant list should have enum ancestor");
147 let enum_def_id = get_def_id(db, &def_loc, enum_node, DefKind::Enum); 141 let enum_def_id = get_def_id(db, &def_loc, enum_node, DefKind::Enum);
148 142
149 Ok(Arc::new(EnumVariantData::new( 143 Arc::new(EnumVariantData::new(variant_def, Enum::new(enum_def_id)))
150 variant_def,
151 Enum::new(enum_def_id),
152 )))
153 } 144 }
154} 145}
155 146
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index db270b871..cd61d922b 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -175,13 +175,12 @@ impl Struct {
175 self.def_id 175 self.def_id
176 } 176 }
177 177
178 pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { 178 pub fn name(&self, db: &impl HirDatabase) -> Option<Name> {
179 Ok(db.struct_data(self.def_id)?.name.clone()) 179 db.struct_data(self.def_id).name.clone()
180 } 180 }
181 181
182 pub fn fields(&self, db: &impl HirDatabase) -> Cancelable<Vec<StructField>> { 182 pub fn fields(&self, db: &impl HirDatabase) -> Vec<StructField> {
183 let res = db 183 db.struct_data(self.def_id)
184 .struct_data(self.def_id)?
185 .variant_data 184 .variant_data
186 .fields() 185 .fields()
187 .iter() 186 .iter()
@@ -189,15 +188,11 @@ impl Struct {
189 struct_: self.clone(), 188 struct_: self.clone(),
190 name: it.name.clone(), 189 name: it.name.clone(),
191 }) 190 })
192 .collect(); 191 .collect()
193 Ok(res)
194 } 192 }
195 193
196 pub fn source( 194 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::StructDef>) {
197 &self, 195 def_id_to_ast(db, self.def_id)
198 db: &impl HirDatabase,
199 ) -> Cancelable<(HirFileId, TreeArc<ast::StructDef>)> {
200 Ok(def_id_to_ast(db, self.def_id))
201 } 196 }
202} 197}
203 198
@@ -215,16 +210,16 @@ impl Enum {
215 self.def_id 210 self.def_id
216 } 211 }
217 212
218 pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { 213 pub fn name(&self, db: &impl HirDatabase) -> Option<Name> {
219 Ok(db.enum_data(self.def_id)?.name.clone()) 214 db.enum_data(self.def_id).name.clone()
220 } 215 }
221 216
222 pub fn variants(&self, db: &impl HirDatabase) -> Cancelable<Vec<(Name, EnumVariant)>> { 217 pub fn variants(&self, db: &impl HirDatabase) -> Vec<(Name, EnumVariant)> {
223 Ok(db.enum_data(self.def_id)?.variants.clone()) 218 db.enum_data(self.def_id).variants.clone()
224 } 219 }
225 220
226 pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::EnumDef>)> { 221 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::EnumDef>) {
227 Ok(def_id_to_ast(db, self.def_id)) 222 def_id_to_ast(db, self.def_id)
228 } 223 }
229} 224}
230 225
@@ -242,23 +237,20 @@ impl EnumVariant {
242 self.def_id 237 self.def_id
243 } 238 }
244 239
245 pub fn parent_enum(&self, db: &impl HirDatabase) -> Cancelable<Enum> { 240 pub fn parent_enum(&self, db: &impl HirDatabase) -> Enum {
246 Ok(db.enum_variant_data(self.def_id)?.parent_enum.clone()) 241 db.enum_variant_data(self.def_id).parent_enum.clone()
247 } 242 }
248 243
249 pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { 244 pub fn name(&self, db: &impl HirDatabase) -> Option<Name> {
250 Ok(db.enum_variant_data(self.def_id)?.name.clone()) 245 db.enum_variant_data(self.def_id).name.clone()
251 } 246 }
252 247
253 pub fn variant_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<VariantData>> { 248 pub fn variant_data(&self, db: &impl HirDatabase) -> Arc<VariantData> {
254 Ok(db.enum_variant_data(self.def_id)?.variant_data.clone()) 249 db.enum_variant_data(self.def_id).variant_data.clone()
255 } 250 }
256 251
257 pub fn source( 252 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::EnumVariant>) {
258 &self, 253 def_id_to_ast(db, self.def_id)
259 db: &impl HirDatabase,
260 ) -> Cancelable<(HirFileId, TreeArc<ast::EnumVariant>)> {
261 Ok(def_id_to_ast(db, self.def_id))
262 } 254 }
263} 255}
264 256
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
index 8668d6c8a..f27523753 100644
--- a/crates/ra_hir/src/code_model_impl/module.rs
+++ b/crates/ra_hir/src/code_model_impl/module.rs
@@ -154,7 +154,7 @@ impl Module {
154 if segments.len() == idx + 1 { 154 if segments.len() == idx + 1 {
155 // enum variant 155 // enum variant
156 let matching_variant = 156 let matching_variant =
157 e.variants(db)?.into_iter().find(|(n, _variant)| n == name); 157 e.variants(db).into_iter().find(|(n, _variant)| n == name);
158 158
159 if let Some((_n, variant)) = matching_variant { 159 if let Some((_n, variant)) = matching_variant {
160 return Ok(PerNs::both(variant.def_id(), e.def_id())); 160 return Ok(PerNs::both(variant.def_id(), e.def_id()));
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs
index 3b2498d5a..6229f9778 100644
--- a/crates/ra_hir/src/db.rs
+++ b/crates/ra_hir/src/db.rs
@@ -37,17 +37,17 @@ pub trait HirDatabase: SyntaxDatabase
37 use fn query_definitions::fn_scopes; 37 use fn query_definitions::fn_scopes;
38 } 38 }
39 39
40 fn struct_data(def_id: DefId) -> Cancelable<Arc<StructData>> { 40 fn struct_data(def_id: DefId) -> Arc<StructData> {
41 type StructDataQuery; 41 type StructDataQuery;
42 use fn crate::adt::StructData::struct_data_query; 42 use fn crate::adt::StructData::struct_data_query;
43 } 43 }
44 44
45 fn enum_data(def_id: DefId) -> Cancelable<Arc<EnumData>> { 45 fn enum_data(def_id: DefId) -> Arc<EnumData> {
46 type EnumDataQuery; 46 type EnumDataQuery;
47 use fn crate::adt::EnumData::enum_data_query; 47 use fn crate::adt::EnumData::enum_data_query;
48 } 48 }
49 49
50 fn enum_variant_data(def_id: DefId) -> Cancelable<Arc<EnumVariantData>> { 50 fn enum_variant_data(def_id: DefId) -> Arc<EnumVariantData> {
51 type EnumVariantDataQuery; 51 type EnumVariantDataQuery;
52 use fn crate::adt::EnumVariantData::enum_variant_data_query; 52 use fn crate::adt::EnumVariantData::enum_variant_data_query;
53 } 53 }
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 03787bd89..b0642d905 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -463,19 +463,19 @@ fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable<Ty> {
463fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Cancelable<Ty> { 463fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Cancelable<Ty> {
464 Ok(Ty::Adt { 464 Ok(Ty::Adt {
465 def_id: s.def_id(), 465 def_id: s.def_id(),
466 name: s.name(db)?.unwrap_or_else(Name::missing), 466 name: s.name(db).unwrap_or_else(Name::missing),
467 }) 467 })
468} 468}
469 469
470pub(crate) fn type_for_enum(db: &impl HirDatabase, s: Enum) -> Cancelable<Ty> { 470pub(crate) fn type_for_enum(db: &impl HirDatabase, s: Enum) -> Cancelable<Ty> {
471 Ok(Ty::Adt { 471 Ok(Ty::Adt {
472 def_id: s.def_id(), 472 def_id: s.def_id(),
473 name: s.name(db)?.unwrap_or_else(Name::missing), 473 name: s.name(db).unwrap_or_else(Name::missing),
474 }) 474 })
475} 475}
476 476
477pub(crate) fn type_for_enum_variant(db: &impl HirDatabase, ev: EnumVariant) -> Cancelable<Ty> { 477pub(crate) fn type_for_enum_variant(db: &impl HirDatabase, ev: EnumVariant) -> Cancelable<Ty> {
478 let enum_parent = ev.parent_enum(db)?; 478 let enum_parent = ev.parent_enum(db);
479 479
480 type_for_enum(db, enum_parent) 480 type_for_enum(db, enum_parent)
481} 481}
@@ -510,7 +510,7 @@ pub(super) fn type_for_field(
510 let def = def_id.resolve(db)?; 510 let def = def_id.resolve(db)?;
511 let variant_data = match def { 511 let variant_data = match def {
512 Def::Struct(s) => s.variant_data(db)?, 512 Def::Struct(s) => s.variant_data(db)?,
513 Def::EnumVariant(ev) => ev.variant_data(db)?, 513 Def::EnumVariant(ev) => ev.variant_data(db),
514 // TODO: unions 514 // TODO: unions
515 _ => panic!( 515 _ => panic!(
516 "trying to get type for field in non-struct/variant {:?}", 516 "trying to get type for field in non-struct/variant {:?}",