diff options
author | Aleksey Kladov <[email protected]> | 2019-11-25 13:16:41 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-25 13:16:41 +0000 |
commit | 9047a4ad4620d3b37d17a11e6dee0ea4ffbd7af1 (patch) | |
tree | 8980df5edec22b1b6dae7bfca05001d34a9f6b9f /crates/ra_hir | |
parent | 1a9717b07241eb8f7610f1ff600b55cf5eaaf75f (diff) |
Use more IDs
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index 1ceafd9b1..348c5f67d 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs | |||
@@ -14,7 +14,7 @@ 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, GenericDefId, LocalStructFieldId, VariantId, | 17 | AdtId, EnumVariantId, FunctionId, GenericDefId, LocalStructFieldId, StructId, VariantId, |
18 | }; | 18 | }; |
19 | use ra_arena::map::ArenaMap; | 19 | use ra_arena::map::ArenaMap; |
20 | 20 | ||
@@ -546,9 +546,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). | 546 | /// 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 { | 547 | pub(crate) fn callable_item_sig(db: &impl HirDatabase, def: CallableDef) -> FnSig { |
548 | match def { | 548 | match def { |
549 | CallableDef::Function(f) => fn_sig_for_fn(db, f), | 549 | CallableDef::Function(f) => fn_sig_for_fn(db, f.id), |
550 | CallableDef::Struct(s) => fn_sig_for_struct_constructor(db, s), | 550 | CallableDef::Struct(s) => fn_sig_for_struct_constructor(db, s.id), |
551 | CallableDef::EnumVariant(e) => fn_sig_for_enum_variant_constructor(db, e), | 551 | CallableDef::EnumVariant(e) => fn_sig_for_enum_variant_constructor(db, e.into()), |
552 | } | 552 | } |
553 | } | 553 | } |
554 | 554 | ||
@@ -630,9 +630,9 @@ pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDefId) - | |||
630 | Substs(defaults) | 630 | Substs(defaults) |
631 | } | 631 | } |
632 | 632 | ||
633 | fn fn_sig_for_fn(db: &impl HirDatabase, def: Function) -> FnSig { | 633 | fn fn_sig_for_fn(db: &impl HirDatabase, def: FunctionId) -> FnSig { |
634 | let data = db.function_data(def.id); | 634 | let data = db.function_data(def); |
635 | let resolver = def.id.resolver(db); | 635 | let resolver = def.resolver(db); |
636 | let params = data.params.iter().map(|tr| Ty::from_hir(db, &resolver, tr)).collect::<Vec<_>>(); | 636 | let params = data.params.iter().map(|tr| Ty::from_hir(db, &resolver, tr)).collect::<Vec<_>>(); |
637 | let ret = Ty::from_hir(db, &resolver, &data.ret_type); | 637 | let ret = Ty::from_hir(db, &resolver, &data.ret_type); |
638 | FnSig::from_params_and_return(params, ret) | 638 | FnSig::from_params_and_return(params, ret) |
@@ -703,15 +703,15 @@ impl From<Option<BuiltinFloat>> for Uncertain<FloatTy> { | |||
703 | } | 703 | } |
704 | } | 704 | } |
705 | 705 | ||
706 | fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> FnSig { | 706 | fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> FnSig { |
707 | let struct_data = db.struct_data(def.id.into()); | 707 | let struct_data = db.struct_data(def.into()); |
708 | let fields = struct_data.variant_data.fields(); | 708 | let fields = struct_data.variant_data.fields(); |
709 | let resolver = def.id.resolver(db); | 709 | let resolver = def.resolver(db); |
710 | let params = fields | 710 | let params = fields |
711 | .iter() | 711 | .iter() |
712 | .map(|(_, field)| Ty::from_hir(db, &resolver, &field.type_ref)) | 712 | .map(|(_, field)| Ty::from_hir(db, &resolver, &field.type_ref)) |
713 | .collect::<Vec<_>>(); | 713 | .collect::<Vec<_>>(); |
714 | let ret = type_for_adt(db, def); | 714 | let ret = type_for_adt(db, Struct::from(def)); |
715 | FnSig::from_params_and_return(params, ret) | 715 | FnSig::from_params_and_return(params, ret) |
716 | } | 716 | } |
717 | 717 | ||
@@ -726,17 +726,18 @@ fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty { | |||
726 | Ty::apply(TypeCtor::FnDef(def.into()), substs) | 726 | Ty::apply(TypeCtor::FnDef(def.into()), substs) |
727 | } | 727 | } |
728 | 728 | ||
729 | fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> FnSig { | 729 | fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId) -> FnSig { |
730 | let var_data = def.variant_data(db); | 730 | let enum_data = db.enum_data(def.parent); |
731 | let fields = var_data.fields(); | 731 | let var_data = &enum_data.variants[def.local_id]; |
732 | let resolver = def.parent.id.resolver(db); | 732 | let fields = var_data.variant_data.fields(); |
733 | let resolver = def.parent.resolver(db); | ||
733 | let params = fields | 734 | let params = fields |
734 | .iter() | 735 | .iter() |
735 | .map(|(_, field)| Ty::from_hir(db, &resolver, &field.type_ref)) | 736 | .map(|(_, field)| Ty::from_hir(db, &resolver, &field.type_ref)) |
736 | .collect::<Vec<_>>(); | 737 | .collect::<Vec<_>>(); |
737 | let generics = db.generic_params(def.parent_enum(db).id.into()); | 738 | let generics = db.generic_params(def.parent.into()); |
738 | let substs = Substs::identity(&generics); | 739 | let substs = Substs::identity(&generics); |
739 | let ret = type_for_adt(db, def.parent_enum(db)).subst(&substs); | 740 | let ret = type_for_adt(db, Enum::from(def.parent)).subst(&substs); |
740 | FnSig::from_params_and_return(params, ret) | 741 | FnSig::from_params_and_return(params, ret) |
741 | } | 742 | } |
742 | 743 | ||