aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-03-16 16:29:55 +0000
committerFlorian Diebold <[email protected]>2019-03-16 16:29:55 +0000
commit7faae12311895b20b4dec47825708d15f3aaf034 (patch)
treedc7298ec39809f520362a5c1fa1dc98ce63900f7 /crates/ra_hir/src/ty
parenta9ddaba905348897606948658798f9f46854acf7 (diff)
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.
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/infer.rs6
-rw-r--r--crates/ra_hir/src/ty/lower.rs18
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).
216pub(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.
216pub(crate) fn type_for_field(db: &impl HirDatabase, field: StructField) -> Ty { 225pub(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.
238fn type_for_fn(db: &impl HirDatabase, def: Function) -> Ty { 247fn 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
288fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariant) -> FnSig { 295fn 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
317fn make_substs(generics: &GenericParams) -> Substs { 323fn make_substs(generics: &GenericParams) -> Substs {