From 7faae12311895b20b4dec47825708d15f3aaf034 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 16 Mar 2019 17:29:55 +0100 Subject: Remove FnSig from FnDef type It doesn't need to be in there since it's just information from the def. Another step towards aligning Ty with Chalk's representation. --- crates/ra_hir/src/ty/infer.rs | 6 ++++-- crates/ra_hir/src/ty/lower.rs | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'crates/ra_hir/src/ty') diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 2eb73726e..c9a5bc7a1 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -725,7 +725,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let callee_ty = self.infer_expr(*callee, &Expectation::none()); let (param_tys, ret_ty) = match &callee_ty { Ty::FnPtr(sig) => (sig.params().to_vec(), sig.ret().clone()), - Ty::FnDef { substs, sig, .. } => { + Ty::FnDef { substs, def, .. } => { + let sig = self.db.callable_item_signature(*def); let ret_ty = sig.ret().clone().subst(&substs); let param_tys = sig.params().iter().map(|ty| ty.clone().subst(&substs)).collect(); @@ -768,7 +769,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { (Ty::Unknown, Vec::new(), sig.ret().clone()) } } - Ty::FnDef { substs, sig, .. } => { + Ty::FnDef { substs, def, .. } => { + let sig = self.db.callable_item_signature(*def); let ret_ty = sig.ret().clone().subst(&substs); if !sig.params().is_empty() { diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs index 7d065203a..278f592d3 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs @@ -212,6 +212,15 @@ 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), + } +} + /// Build the type of a specific field of a struct or enum variant. pub(crate) fn type_for_field(db: &impl HirDatabase, field: StructField) -> Ty { let parent_def = field.parent_def(db); @@ -236,10 +245,9 @@ fn fn_sig_for_fn(db: &impl HirDatabase, def: Function) -> FnSig { /// Build the declared type of a function. This should not need to look at the /// function body. fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty { - let sig = fn_sig_for_fn(db, def); let generics = def.generic_params(db); let substs = make_substs(&generics); - Ty::FnDef { def: def.into(), sig, substs } + Ty::FnDef { def: def.into(), substs } } /// Build the declared type of a const. @@ -279,10 +287,9 @@ fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty { if var_data.fields().is_none() { return type_for_struct(db, def); // Unit struct } - let sig = fn_sig_for_struct_constructor(db, def); let generics = def.generic_params(db); let substs = make_substs(&generics); - Ty::FnDef { def: def.into(), sig, substs } + Ty::FnDef { def: def.into(), substs } } fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> FnSig { @@ -308,10 +315,9 @@ fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> if var_data.fields().is_none() { return type_for_enum(db, def.parent_enum(db)); // Unit variant } - let sig = fn_sig_for_enum_variant_constructor(db, def); let generics = def.parent_enum(db).generic_params(db); let substs = make_substs(&generics); - Ty::FnDef { def: def.into(), sig, substs } + Ty::FnDef { def: def.into(), substs } } fn make_substs(generics: &GenericParams) -> Substs { -- cgit v1.2.3