aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-15 15:50:47 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-15 15:50:47 +0000
commit7c977a7dcd2bac3b6148f2428bcb586c6354d775 (patch)
tree6ea2db9840f91aa39b65680ace9d3079a140a12c /crates/ra_hir/src
parent05149d353299b54476410daeda6551e1261128ef (diff)
parentf1367e0370d5de5cba13c853c7df5f0c5a0edf59 (diff)
Merge #552
552: remove Cancelable from navigation target r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/adt.rs23
-rw-r--r--crates/ra_hir/src/code_model_api.rs73
-rw-r--r--crates/ra_hir/src/code_model_impl/module.rs4
-rw-r--r--crates/ra_hir/src/db.rs6
-rw-r--r--crates/ra_hir/src/expr.rs4
-rw-r--r--crates/ra_hir/src/ids.rs7
-rw-r--r--crates/ra_hir/src/ty.rs14
7 files changed, 55 insertions, 76 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..f28e077c6 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
@@ -305,8 +297,8 @@ impl Function {
305 self.def_id 297 self.def_id
306 } 298 }
307 299
308 pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::FnDef>)> { 300 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::FnDef>) {
309 Ok(def_id_to_ast(db, self.def_id)) 301 def_id_to_ast(db, self.def_id)
310 } 302 }
311 303
312 pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Cancelable<Arc<BodySyntaxMapping>> { 304 pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Cancelable<Arc<BodySyntaxMapping>> {
@@ -341,8 +333,8 @@ impl Const {
341 Const { def_id } 333 Const { def_id }
342 } 334 }
343 335
344 pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::ConstDef>)> { 336 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::ConstDef>) {
345 Ok(def_id_to_ast(db, self.def_id)) 337 def_id_to_ast(db, self.def_id)
346 } 338 }
347} 339}
348 340
@@ -356,11 +348,8 @@ impl Static {
356 Static { def_id } 348 Static { def_id }
357 } 349 }
358 350
359 pub fn source( 351 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::StaticDef>) {
360 &self, 352 def_id_to_ast(db, self.def_id)
361 db: &impl HirDatabase,
362 ) -> Cancelable<(HirFileId, TreeArc<ast::StaticDef>)> {
363 Ok(def_id_to_ast(db, self.def_id))
364 } 353 }
365} 354}
366 355
@@ -374,8 +363,8 @@ impl Trait {
374 Trait { def_id } 363 Trait { def_id }
375 } 364 }
376 365
377 pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::TraitDef>)> { 366 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::TraitDef>) {
378 Ok(def_id_to_ast(db, self.def_id)) 367 def_id_to_ast(db, self.def_id)
379 } 368 }
380} 369}
381 370
@@ -389,7 +378,7 @@ impl Type {
389 Type { def_id } 378 Type { def_id }
390 } 379 }
391 380
392 pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::TypeDef>)> { 381 pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::TypeDef>) {
393 Ok(def_id_to_ast(db, self.def_id)) 382 def_id_to_ast(db, self.def_id)
394 } 383 }
395} 384}
diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs
index 8668d6c8a..331b0500e 100644
--- a/crates/ra_hir/src/code_model_impl/module.rs
+++ b/crates/ra_hir/src/code_model_impl/module.rs
@@ -148,13 +148,13 @@ impl Module {
148 } else { 148 } else {
149 return Ok(PerNs::none()); 149 return Ok(PerNs::none());
150 }; 150 };
151 let module = match curr.resolve(db)? { 151 let module = match curr.resolve(db) {
152 Def::Module(it) => it, 152 Def::Module(it) => it,
153 Def::Enum(e) => { 153 Def::Enum(e) => {
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/expr.rs b/crates/ra_hir/src/expr.rs
index 5081466a2..a1e8da348 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -832,10 +832,10 @@ pub(crate) fn body_syntax_mapping(
832 db: &impl HirDatabase, 832 db: &impl HirDatabase,
833 def_id: DefId, 833 def_id: DefId,
834) -> Cancelable<Arc<BodySyntaxMapping>> { 834) -> Cancelable<Arc<BodySyntaxMapping>> {
835 let def = def_id.resolve(db)?; 835 let def = def_id.resolve(db);
836 836
837 let body_syntax_mapping = match def { 837 let body_syntax_mapping = match def {
838 Def::Function(f) => collect_fn_body_syntax(&f.source(db)?.1), 838 Def::Function(f) => collect_fn_body_syntax(&f.source(db).1),
839 // TODO: consts, etc. 839 // TODO: consts, etc.
840 _ => panic!("Trying to get body for item type without body"), 840 _ => panic!("Trying to get body for item type without body"),
841 }; 841 };
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs
index 7b572061a..3cbf8070f 100644
--- a/crates/ra_hir/src/ids.rs
+++ b/crates/ra_hir/src/ids.rs
@@ -159,9 +159,9 @@ impl DefId {
159 db.as_ref().id2loc(self) 159 db.as_ref().id2loc(self)
160 } 160 }
161 161
162 pub fn resolve(self, db: &impl HirDatabase) -> Cancelable<Def> { 162 pub fn resolve(self, db: &impl HirDatabase) -> Def {
163 let loc = self.loc(db); 163 let loc = self.loc(db);
164 let res = match loc.kind { 164 match loc.kind {
165 DefKind::Module => { 165 DefKind::Module => {
166 let module = Module::from_module_id(db, loc.source_root_id, loc.module_id); 166 let module = Module::from_module_id(db, loc.source_root_id, loc.module_id);
167 Def::Module(module) 167 Def::Module(module)
@@ -195,8 +195,7 @@ impl DefId {
195 195
196 DefKind::StructCtor => Def::Item, 196 DefKind::StructCtor => Def::Item,
197 DefKind::Item => Def::Item, 197 DefKind::Item => Def::Item,
198 }; 198 }
199 Ok(res)
200 } 199 }
201 200
202 pub(crate) fn source(self, db: &impl HirDatabase) -> (HirFileId, TreeArc<SyntaxNode>) { 201 pub(crate) fn source(self, db: &impl HirDatabase) -> (HirFileId, TreeArc<SyntaxNode>) {
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 03787bd89..3607969ed 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -463,25 +463,25 @@ 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}
482 482
483pub(super) fn type_for_def(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Ty> { 483pub(super) fn type_for_def(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Ty> {
484 let def = def_id.resolve(db)?; 484 let def = def_id.resolve(db);
485 match def { 485 match def {
486 Def::Module(..) => { 486 Def::Module(..) => {
487 log::debug!("trying to get type for module {:?}", def_id); 487 log::debug!("trying to get type for module {:?}", def_id);
@@ -507,10 +507,10 @@ pub(super) fn type_for_field(
507 def_id: DefId, 507 def_id: DefId,
508 field: Name, 508 field: Name,
509) -> Cancelable<Option<Ty>> { 509) -> Cancelable<Option<Ty>> {
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 {:?}",
@@ -877,7 +877,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
877 } else { 877 } else {
878 return Ok((Ty::Unknown, None)); 878 return Ok((Ty::Unknown, None));
879 }; 879 };
880 Ok(match def_id.resolve(self.db)? { 880 Ok(match def_id.resolve(self.db) {
881 Def::Struct(s) => { 881 Def::Struct(s) => {
882 let ty = type_for_struct(self.db, s)?; 882 let ty = type_for_struct(self.db, s)?;
883 (ty, Some(def_id)) 883 (ty, Some(def_id))