diff options
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 03787bd89..e5f8ffc2e 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -349,7 +349,7 @@ impl Ty { | |||
349 | } | 349 | } |
350 | 350 | ||
351 | // Resolve in module (in type namespace) | 351 | // Resolve in module (in type namespace) |
352 | let resolved = if let Some(r) = module.resolve_path(db, path)?.take_types() { | 352 | let resolved = if let Some(r) = module.resolve_path(db, path).take_types() { |
353 | r | 353 | r |
354 | } else { | 354 | } else { |
355 | return Ok(Ty::Unknown); | 355 | return Ok(Ty::Unknown); |
@@ -447,8 +447,8 @@ impl fmt::Display for Ty { | |||
447 | /// function body. | 447 | /// function body. |
448 | fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable<Ty> { | 448 | fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable<Ty> { |
449 | let signature = f.signature(db); | 449 | let signature = f.signature(db); |
450 | let module = f.module(db)?; | 450 | let module = f.module(db); |
451 | let impl_block = f.impl_block(db)?; | 451 | let impl_block = f.impl_block(db); |
452 | // TODO we ignore type parameters for now | 452 | // TODO we ignore type parameters for now |
453 | let input = signature | 453 | let input = signature |
454 | .params() | 454 | .params() |
@@ -463,25 +463,25 @@ fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable<Ty> { | |||
463 | fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Cancelable<Ty> { | 463 | fn 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 | ||
470 | pub(crate) fn type_for_enum(db: &impl HirDatabase, s: Enum) -> Cancelable<Ty> { | 470 | pub(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 | ||
477 | pub(crate) fn type_for_enum_variant(db: &impl HirDatabase, ev: EnumVariant) -> Cancelable<Ty> { | 477 | pub(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 | ||
483 | pub(super) fn type_for_def(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Ty> { | 483 | pub(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,18 +507,18 @@ 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 {:?}", |
517 | def_id | 517 | def_id |
518 | ), | 518 | ), |
519 | }; | 519 | }; |
520 | let module = def_id.module(db)?; | 520 | let module = def_id.module(db); |
521 | let impl_block = def_id.impl_block(db)?; | 521 | let impl_block = def_id.impl_block(db); |
522 | let type_ref = ctry!(variant_data.get_field_type_ref(&field)); | 522 | let type_ref = ctry!(variant_data.get_field_type_ref(&field)); |
523 | Ok(Some(Ty::from_hir( | 523 | Ok(Some(Ty::from_hir( |
524 | db, | 524 | db, |
@@ -860,7 +860,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
860 | }; | 860 | }; |
861 | 861 | ||
862 | // resolve in module | 862 | // resolve in module |
863 | let resolved = ctry!(self.module.resolve_path(self.db, &path)?.take_values()); | 863 | let resolved = ctry!(self.module.resolve_path(self.db, &path).take_values()); |
864 | let ty = self.db.type_for_def(resolved)?; | 864 | let ty = self.db.type_for_def(resolved)?; |
865 | let ty = self.insert_type_vars(ty); | 865 | let ty = self.insert_type_vars(ty); |
866 | Ok(Some(ty)) | 866 | Ok(Some(ty)) |
@@ -872,12 +872,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
872 | } else { | 872 | } else { |
873 | return Ok((Ty::Unknown, None)); | 873 | return Ok((Ty::Unknown, None)); |
874 | }; | 874 | }; |
875 | let def_id = if let Some(def_id) = self.module.resolve_path(self.db, &path)?.take_types() { | 875 | let def_id = if let Some(def_id) = self.module.resolve_path(self.db, &path).take_types() { |
876 | def_id | 876 | def_id |
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)) |
@@ -1205,10 +1205,10 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1205 | pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> { | 1205 | pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> { |
1206 | db.check_canceled(); | 1206 | db.check_canceled(); |
1207 | let function = Function::new(def_id); // TODO: consts also need inference | 1207 | let function = Function::new(def_id); // TODO: consts also need inference |
1208 | let body = function.body(db)?; | 1208 | let body = function.body(db); |
1209 | let scopes = db.fn_scopes(def_id)?; | 1209 | let scopes = db.fn_scopes(def_id); |
1210 | let module = function.module(db)?; | 1210 | let module = function.module(db); |
1211 | let impl_block = function.impl_block(db)?; | 1211 | let impl_block = function.impl_block(db); |
1212 | let mut ctx = InferenceContext::new(db, body, scopes, module, impl_block); | 1212 | let mut ctx = InferenceContext::new(db, body, scopes, module, impl_block); |
1213 | 1213 | ||
1214 | let signature = function.signature(db); | 1214 | let signature = function.signature(db); |