diff options
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 18 |
2 files changed, 16 insertions, 8 deletions
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> { | |||
725 | let callee_ty = self.infer_expr(*callee, &Expectation::none()); | 725 | let callee_ty = self.infer_expr(*callee, &Expectation::none()); |
726 | let (param_tys, ret_ty) = match &callee_ty { | 726 | let (param_tys, ret_ty) = match &callee_ty { |
727 | Ty::FnPtr(sig) => (sig.params().to_vec(), sig.ret().clone()), | 727 | Ty::FnPtr(sig) => (sig.params().to_vec(), sig.ret().clone()), |
728 | Ty::FnDef { substs, sig, .. } => { | 728 | Ty::FnDef { substs, def, .. } => { |
729 | let sig = self.db.callable_item_signature(*def); | ||
729 | let ret_ty = sig.ret().clone().subst(&substs); | 730 | let ret_ty = sig.ret().clone().subst(&substs); |
730 | let param_tys = | 731 | let param_tys = |
731 | sig.params().iter().map(|ty| ty.clone().subst(&substs)).collect(); | 732 | sig.params().iter().map(|ty| ty.clone().subst(&substs)).collect(); |
@@ -768,7 +769,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
768 | (Ty::Unknown, Vec::new(), sig.ret().clone()) | 769 | (Ty::Unknown, Vec::new(), sig.ret().clone()) |
769 | } | 770 | } |
770 | } | 771 | } |
771 | Ty::FnDef { substs, sig, .. } => { | 772 | Ty::FnDef { substs, def, .. } => { |
773 | let sig = self.db.callable_item_signature(*def); | ||
772 | let ret_ty = sig.ret().clone().subst(&substs); | 774 | let ret_ty = sig.ret().clone().subst(&substs); |
773 | 775 | ||
774 | if !sig.params().is_empty() { | 776 | 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 | |||
212 | } | 212 | } |
213 | } | 213 | } |
214 | 214 | ||
215 | /// Build the signature of a callable item (function, struct or enum variant). | ||
216 | pub(crate) fn callable_item_sig(db: &impl HirDatabase, def: CallableDef) -> FnSig { | ||
217 | match def { | ||
218 | CallableDef::Function(f) => fn_sig_for_fn(db, f), | ||
219 | CallableDef::Struct(s) => fn_sig_for_struct_constructor(db, s), | ||
220 | CallableDef::EnumVariant(e) => fn_sig_for_enum_variant_constructor(db, e), | ||
221 | } | ||
222 | } | ||
223 | |||
215 | /// Build the type of a specific field of a struct or enum variant. | 224 | /// Build the type of a specific field of a struct or enum variant. |
216 | pub(crate) fn type_for_field(db: &impl HirDatabase, field: StructField) -> Ty { | 225 | pub(crate) fn type_for_field(db: &impl HirDatabase, field: StructField) -> Ty { |
217 | let parent_def = field.parent_def(db); | 226 | let parent_def = field.parent_def(db); |
@@ -236,10 +245,9 @@ fn fn_sig_for_fn(db: &impl HirDatabase, def: Function) -> FnSig { | |||
236 | /// Build the declared type of a function. This should not need to look at the | 245 | /// Build the declared type of a function. This should not need to look at the |
237 | /// function body. | 246 | /// function body. |
238 | fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty { | 247 | fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty { |
239 | let sig = fn_sig_for_fn(db, def); | ||
240 | let generics = def.generic_params(db); | 248 | let generics = def.generic_params(db); |
241 | let substs = make_substs(&generics); | 249 | let substs = make_substs(&generics); |
242 | Ty::FnDef { def: def.into(), sig, substs } | 250 | Ty::FnDef { def: def.into(), substs } |
243 | } | 251 | } |
244 | 252 | ||
245 | /// Build the declared type of a const. | 253 | /// Build the declared type of a const. |
@@ -279,10 +287,9 @@ fn type_for_struct_constructor(db: &impl HirDatabase, def: Struct) -> Ty { | |||
279 | if var_data.fields().is_none() { | 287 | if var_data.fields().is_none() { |
280 | return type_for_struct(db, def); // Unit struct | 288 | return type_for_struct(db, def); // Unit struct |
281 | } | 289 | } |
282 | let sig = fn_sig_for_struct_constructor(db, def); | ||
283 | let generics = def.generic_params(db); | 290 | let generics = def.generic_params(db); |
284 | let substs = make_substs(&generics); | 291 | let substs = make_substs(&generics); |
285 | Ty::FnDef { def: def.into(), sig, substs } | 292 | Ty::FnDef { def: def.into(), substs } |
286 | } | 293 | } |
287 | 294 | ||
288 | fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> FnSig { | 295 | 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) -> | |||
308 | if var_data.fields().is_none() { | 315 | if var_data.fields().is_none() { |
309 | return type_for_enum(db, def.parent_enum(db)); // Unit variant | 316 | return type_for_enum(db, def.parent_enum(db)); // Unit variant |
310 | } | 317 | } |
311 | let sig = fn_sig_for_enum_variant_constructor(db, def); | ||
312 | let generics = def.parent_enum(db).generic_params(db); | 318 | let generics = def.parent_enum(db).generic_params(db); |
313 | let substs = make_substs(&generics); | 319 | let substs = make_substs(&generics); |
314 | Ty::FnDef { def: def.into(), sig, substs } | 320 | Ty::FnDef { def: def.into(), substs } |
315 | } | 321 | } |
316 | 322 | ||
317 | fn make_substs(generics: &GenericParams) -> Substs { | 323 | fn make_substs(generics: &GenericParams) -> Substs { |