Use more IDs

This commit is contained in:
Aleksey Kladov 2019-11-25 16:16:41 +03:00
parent 1a9717b072
commit 9047a4ad46

View file

@ -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::<Vec<_>>();
let ret = Ty::from_hir(db, &resolver, &data.ret_type);
FnSig::from_params_and_return(params, ret)
@ -703,15 +703,15 @@ impl From<Option<BuiltinFloat>> for Uncertain<FloatTy> {
}
}
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::<Vec<_>>();
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::<Vec<_>>();
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)
}