aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/lower.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty/lower.rs')
-rw-r--r--crates/ra_hir/src/ty/lower.rs18
1 files changed, 12 insertions, 6 deletions
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 {