From 9047a4ad4620d3b37d17a11e6dee0ea4ffbd7af1 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 25 Nov 2019 16:16:41 +0300 Subject: Use more IDs --- crates/ra_hir/src/ty/lower.rs | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'crates/ra_hir') 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::{ path::{GenericArg, PathSegment}, resolver::{HasResolver, Resolver, TypeNs}, type_ref::{TypeBound, TypeRef}, - AdtId, EnumVariantId, GenericDefId, LocalStructFieldId, VariantId, + AdtId, EnumVariantId, FunctionId, GenericDefId, LocalStructFieldId, StructId, VariantId, }; use ra_arena::map::ArenaMap; @@ -546,9 +546,9 @@ pub(crate) fn type_for_def(db: &impl HirDatabase, def: TypableDef, ns: Namespace /// Build the signature of a callable item (function, struct or enum variant). pub(crate) fn callable_item_sig(db: &impl HirDatabase, def: CallableDef) -> FnSig { match def { - CallableDef::Function(f) => fn_sig_for_fn(db, f), - CallableDef::Struct(s) => fn_sig_for_struct_constructor(db, s), - CallableDef::EnumVariant(e) => fn_sig_for_enum_variant_constructor(db, e), + CallableDef::Function(f) => fn_sig_for_fn(db, f.id), + CallableDef::Struct(s) => fn_sig_for_struct_constructor(db, s.id), + CallableDef::EnumVariant(e) => fn_sig_for_enum_variant_constructor(db, e.into()), } } @@ -630,9 +630,9 @@ pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDefId) - Substs(defaults) } -fn fn_sig_for_fn(db: &impl HirDatabase, def: Function) -> FnSig { - let data = db.function_data(def.id); - let resolver = def.id.resolver(db); +fn fn_sig_for_fn(db: &impl HirDatabase, def: FunctionId) -> FnSig { + let data = db.function_data(def); + let resolver = def.resolver(db); let params = data.params.iter().map(|tr| Ty::from_hir(db, &resolver, tr)).collect::>(); let ret = Ty::from_hir(db, &resolver, &data.ret_type); FnSig::from_params_and_return(params, ret) @@ -703,15 +703,15 @@ impl From> for Uncertain { } } -fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> FnSig { - let struct_data = db.struct_data(def.id.into()); +fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> FnSig { + let struct_data = db.struct_data(def.into()); let fields = struct_data.variant_data.fields(); - let resolver = def.id.resolver(db); + let resolver = def.resolver(db); let params = fields .iter() .map(|(_, field)| Ty::from_hir(db, &resolver, &field.type_ref)) .collect::>(); - let ret = type_for_adt(db, def); + let ret = type_for_adt(db, Struct::from(def)); FnSig::from_params_and_return(params, ret) } @@ -726,17 +726,18 @@ fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty { Ty::apply(TypeCtor::FnDef(def.into()), substs) } -fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> FnSig { - let var_data = def.variant_data(db); - let fields = var_data.fields(); - let resolver = def.parent.id.resolver(db); +fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId) -> FnSig { + let enum_data = db.enum_data(def.parent); + let var_data = &enum_data.variants[def.local_id]; + let fields = var_data.variant_data.fields(); + let resolver = def.parent.resolver(db); let params = fields .iter() .map(|(_, field)| Ty::from_hir(db, &resolver, &field.type_ref)) .collect::>(); - let generics = db.generic_params(def.parent_enum(db).id.into()); + let generics = db.generic_params(def.parent.into()); let substs = Substs::identity(&generics); - let ret = type_for_adt(db, def.parent_enum(db)).subst(&substs); + let ret = type_for_adt(db, Enum::from(def.parent)).subst(&substs); FnSig::from_params_and_return(params, ret) } -- cgit v1.2.3