diff options
author | Aleksey Kladov <[email protected]> | 2019-11-25 13:26:52 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-25 13:26:52 +0000 |
commit | 78791d6fac1ff426264e636545a07664d83d2039 (patch) | |
tree | bd0825246d6f26f7831f50dad8e39a131848a513 /crates/ra_hir/src/ty/lower.rs | |
parent | 9047a4ad4620d3b37d17a11e6dee0ea4ffbd7af1 (diff) |
Use ids for Callable
Diffstat (limited to 'crates/ra_hir/src/ty/lower.rs')
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index 348c5f67d..27cfe00c1 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs | |||
@@ -14,9 +14,11 @@ use hir_def::{ | |||
14 | path::{GenericArg, PathSegment}, | 14 | path::{GenericArg, PathSegment}, |
15 | resolver::{HasResolver, Resolver, TypeNs}, | 15 | resolver::{HasResolver, Resolver, TypeNs}, |
16 | type_ref::{TypeBound, TypeRef}, | 16 | type_ref::{TypeBound, TypeRef}, |
17 | AdtId, EnumVariantId, FunctionId, GenericDefId, LocalStructFieldId, StructId, VariantId, | 17 | AdtId, AstItemDef, EnumVariantId, FunctionId, GenericDefId, HasModule, LocalStructFieldId, |
18 | Lookup, StructId, VariantId, | ||
18 | }; | 19 | }; |
19 | use ra_arena::map::ArenaMap; | 20 | use ra_arena::map::ArenaMap; |
21 | use ra_db::CrateId; | ||
20 | 22 | ||
21 | use super::{ | 23 | use super::{ |
22 | FnSig, GenericPredicate, ProjectionPredicate, ProjectionTy, Substs, TraitEnvironment, TraitRef, | 24 | FnSig, GenericPredicate, ProjectionPredicate, ProjectionTy, Substs, TraitEnvironment, TraitRef, |
@@ -546,9 +548,9 @@ pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace | |||
546 | /// Build the signature of a callable item (function, struct or enum variant). | 548 | /// Build the signature of a callable item (function, struct or enum variant). |
547 | pub(crate) fn callable_item_sig(db: &impl HirDatabase, def: CallableDef) -> FnSig { | 549 | pub(crate) fn callable_item_sig(db: &impl HirDatabase, def: CallableDef) -> FnSig { |
548 | match def { | 550 | match def { |
549 | CallableDef::Function(f) => fn_sig_for_fn(db, f.id), | 551 | CallableDef::FunctionId(f) => fn_sig_for_fn(db, f), |
550 | CallableDef::Struct(s) => fn_sig_for_struct_constructor(db, s.id), | 552 | CallableDef::StructId(s) => fn_sig_for_struct_constructor(db, s), |
551 | CallableDef::EnumVariant(e) => fn_sig_for_enum_variant_constructor(db, e.into()), | 553 | CallableDef::EnumVariantId(e) => fn_sig_for_enum_variant_constructor(db, e), |
552 | } | 554 | } |
553 | } | 555 | } |
554 | 556 | ||
@@ -643,7 +645,7 @@ fn fn_sig_for_fn(db: &impl HirDatabase, def: FunctionId) -> FnSig { | |||
643 | fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty { | 645 | fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty { |
644 | let generics = db.generic_params(def.id.into()); | 646 | let generics = db.generic_params(def.id.into()); |
645 | let substs = Substs::identity(&generics); | 647 | let substs = Substs::identity(&generics); |
646 | Ty::apply(TypeCtor::FnDef(def.into()), substs) | 648 | Ty::apply(TypeCtor::FnDef(def.id.into()), substs) |
647 | } | 649 | } |
648 | 650 | ||
649 | /// Build the declared type of a const. | 651 | /// Build the declared type of a const. |
@@ -723,7 +725,7 @@ fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty { | |||
723 | } | 725 | } |
724 | let generics = db.generic_params(def.id.into()); | 726 | let generics = db.generic_params(def.id.into()); |
725 | let substs = Substs::identity(&generics); | 727 | let substs = Substs::identity(&generics); |
726 | Ty::apply(TypeCtor::FnDef(def.into()), substs) | 728 | Ty::apply(TypeCtor::FnDef(def.id.into()), substs) |
727 | } | 729 | } |
728 | 730 | ||
729 | fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId) -> FnSig { | 731 | fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId) -> FnSig { |
@@ -749,7 +751,7 @@ fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> | |||
749 | } | 751 | } |
750 | let generics = db.generic_params(def.parent_enum(db).id.into()); | 752 | let generics = db.generic_params(def.parent_enum(db).id.into()); |
751 | let substs = Substs::identity(&generics); | 753 | let substs = Substs::identity(&generics); |
752 | Ty::apply(TypeCtor::FnDef(def.into()), substs) | 754 | Ty::apply(TypeCtor::FnDef(EnumVariantId::from(def).into()), substs) |
753 | } | 755 | } |
754 | 756 | ||
755 | fn type_for_adt(db: &impl HirDatabase, adt: impl Into<Adt>) -> Ty { | 757 | fn type_for_adt(db: &impl HirDatabase, adt: impl Into<Adt>) -> Ty { |
@@ -806,18 +808,18 @@ impl From<ModuleDef> for Option<TypableDef> { | |||
806 | 808 | ||
807 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 809 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
808 | pub enum CallableDef { | 810 | pub enum CallableDef { |
809 | Function(Function), | 811 | FunctionId(FunctionId), |
810 | Struct(Struct), | 812 | StructId(StructId), |
811 | EnumVariant(EnumVariant), | 813 | EnumVariantId(EnumVariantId), |
812 | } | 814 | } |
813 | impl_froms!(CallableDef: Function, Struct, EnumVariant); | 815 | impl_froms!(CallableDef: FunctionId, StructId, EnumVariantId); |
814 | 816 | ||
815 | impl CallableDef { | 817 | impl CallableDef { |
816 | pub fn krate(self, db: &impl HirDatabase) -> Option<crate::Crate> { | 818 | pub fn krate(self, db: &impl HirDatabase) -> CrateId { |
817 | match self { | 819 | match self { |
818 | CallableDef::Function(f) => f.krate(db), | 820 | CallableDef::FunctionId(f) => f.lookup(db).module(db).krate, |
819 | CallableDef::Struct(s) => s.krate(db), | 821 | CallableDef::StructId(s) => s.0.module(db).krate, |
820 | CallableDef::EnumVariant(e) => e.parent_enum(db).krate(db), | 822 | CallableDef::EnumVariantId(e) => e.parent.module(db).krate, |
821 | } | 823 | } |
822 | } | 824 | } |
823 | } | 825 | } |
@@ -825,9 +827,9 @@ impl CallableDef { | |||
825 | impl From<CallableDef> for GenericDefId { | 827 | impl From<CallableDef> for GenericDefId { |
826 | fn from(def: CallableDef) -> GenericDefId { | 828 | fn from(def: CallableDef) -> GenericDefId { |
827 | match def { | 829 | match def { |
828 | CallableDef::Function(f) => f.id.into(), | 830 | CallableDef::FunctionId(f) => f.into(), |
829 | CallableDef::Struct(s) => s.id.into(), | 831 | CallableDef::StructId(s) => s.into(), |
830 | CallableDef::EnumVariant(e) => EnumVariantId::from(e).into(), | 832 | CallableDef::EnumVariantId(e) => e.into(), |
831 | } | 833 | } |
832 | } | 834 | } |
833 | } | 835 | } |