diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-02-28 22:54:07 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-02-28 22:54:07 +0000 |
commit | 5df3ee8274fdb7cdeb2b0871b4efea8cbf4724a1 (patch) | |
tree | c1769a152888b97134e3f3811d4504f467ce1047 /crates/hir_ty/src/lower.rs | |
parent | 72457d022d704c47ab9dbfee6a1b29063cc9cc5d (diff) | |
parent | 407196b8c0f23e3ddc26e789b84542b1fd9b0eb8 (diff) |
Merge #7816
7816: Lift Ty::Fn into a struct r=Veykril a=Veykril
bors r+
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/lower.rs')
-rw-r--r-- | crates/hir_ty/src/lower.rs | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 84734bc0b..44bd95a9a 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs | |||
@@ -31,9 +31,9 @@ use crate::{ | |||
31 | all_super_trait_refs, associated_type_by_name_including_super_traits, generics, | 31 | all_super_trait_refs, associated_type_by_name_including_super_traits, generics, |
32 | make_mut_slice, variant_data, | 32 | make_mut_slice, variant_data, |
33 | }, | 33 | }, |
34 | Binders, BoundVar, DebruijnIndex, FnSig, GenericPredicate, OpaqueTy, OpaqueTyId, PolyFnSig, | 34 | Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, GenericPredicate, OpaqueTy, |
35 | ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, ReturnTypeImplTraits, Substs, | 35 | OpaqueTyId, PolyFnSig, ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, |
36 | TraitEnvironment, TraitRef, Ty, TypeWalk, | 36 | ReturnTypeImplTraits, Substs, TraitEnvironment, TraitRef, Ty, TypeWalk, |
37 | }; | 37 | }; |
38 | 38 | ||
39 | #[derive(Debug)] | 39 | #[derive(Debug)] |
@@ -173,8 +173,12 @@ impl Ty { | |||
173 | } | 173 | } |
174 | TypeRef::Placeholder => Ty::Unknown, | 174 | TypeRef::Placeholder => Ty::Unknown, |
175 | TypeRef::Fn(params, is_varargs) => { | 175 | TypeRef::Fn(params, is_varargs) => { |
176 | let sig = Substs(params.iter().map(|tr| Ty::from_hir(ctx, tr)).collect()); | 176 | let substs = Substs(params.iter().map(|tr| Ty::from_hir(ctx, tr)).collect()); |
177 | Ty::FnPtr { num_args: sig.len() as u16 - 1, is_varargs: *is_varargs, substs: sig } | 177 | Ty::Function(FnPointer { |
178 | num_args: substs.len() - 1, | ||
179 | sig: FnSig { variadic: *is_varargs }, | ||
180 | substs, | ||
181 | }) | ||
178 | } | 182 | } |
179 | TypeRef::DynTrait(bounds) => { | 183 | TypeRef::DynTrait(bounds) => { |
180 | let self_ty = Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0)); | 184 | let self_ty = Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0)); |
@@ -1010,7 +1014,7 @@ fn fn_sig_for_fn(db: &dyn HirDatabase, def: FunctionId) -> PolyFnSig { | |||
1010 | let ret = Ty::from_hir(&ctx_ret, &data.ret_type); | 1014 | let ret = Ty::from_hir(&ctx_ret, &data.ret_type); |
1011 | let generics = generics(db.upcast(), def.into()); | 1015 | let generics = generics(db.upcast(), def.into()); |
1012 | let num_binders = generics.len(); | 1016 | let num_binders = generics.len(); |
1013 | Binders::new(num_binders, FnSig::from_params_and_return(params, ret, data.is_varargs)) | 1017 | Binders::new(num_binders, CallableSig::from_params_and_return(params, ret, data.is_varargs)) |
1014 | } | 1018 | } |
1015 | 1019 | ||
1016 | /// Build the declared type of a function. This should not need to look at the | 1020 | /// Build the declared type of a function. This should not need to look at the |
@@ -1050,7 +1054,7 @@ fn fn_sig_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> PolyFnS | |||
1050 | let params = | 1054 | let params = |
1051 | fields.iter().map(|(_, field)| Ty::from_hir(&ctx, &field.type_ref)).collect::<Vec<_>>(); | 1055 | fields.iter().map(|(_, field)| Ty::from_hir(&ctx, &field.type_ref)).collect::<Vec<_>>(); |
1052 | let ret = type_for_adt(db, def.into()); | 1056 | let ret = type_for_adt(db, def.into()); |
1053 | Binders::new(ret.num_binders, FnSig::from_params_and_return(params, ret.value, false)) | 1057 | Binders::new(ret.num_binders, CallableSig::from_params_and_return(params, ret.value, false)) |
1054 | } | 1058 | } |
1055 | 1059 | ||
1056 | /// Build the type of a tuple struct constructor. | 1060 | /// Build the type of a tuple struct constructor. |
@@ -1074,7 +1078,7 @@ fn fn_sig_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) | |||
1074 | let params = | 1078 | let params = |
1075 | fields.iter().map(|(_, field)| Ty::from_hir(&ctx, &field.type_ref)).collect::<Vec<_>>(); | 1079 | fields.iter().map(|(_, field)| Ty::from_hir(&ctx, &field.type_ref)).collect::<Vec<_>>(); |
1076 | let ret = type_for_adt(db, def.parent.into()); | 1080 | let ret = type_for_adt(db, def.parent.into()); |
1077 | Binders::new(ret.num_binders, FnSig::from_params_and_return(params, ret.value, false)) | 1081 | Binders::new(ret.num_binders, CallableSig::from_params_and_return(params, ret.value, false)) |
1078 | } | 1082 | } |
1079 | 1083 | ||
1080 | /// Build the type of a tuple enum variant constructor. | 1084 | /// Build the type of a tuple enum variant constructor. |