aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/lower.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-04-01 20:04:02 +0100
committerFlorian Diebold <[email protected]>2021-04-03 10:17:13 +0100
commite480d81988fc0c0e4f80f1c54058b95b9aaf1ebf (patch)
tree079dabc4e0de72e30d2bd04bd50427ff6950b348 /crates/hir_ty/src/lower.rs
parent327f3a0a3017e047be58b8312f8bf3ac690db3fd (diff)
Introduce `GenericArg` like in Chalk
Plus some more adaptations to Substitution. Lots of `assert_ty_ref` that we should revisit when introducing lifetime/const parameters.
Diffstat (limited to 'crates/hir_ty/src/lower.rs')
-rw-r--r--crates/hir_ty/src/lower.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 72ee060e0..f595683e5 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -178,9 +178,10 @@ impl<'a> TyLoweringContext<'a> {
178 } 178 }
179 TypeRef::Placeholder => TyKind::Unknown.intern(&Interner), 179 TypeRef::Placeholder => TyKind::Unknown.intern(&Interner),
180 TypeRef::Fn(params, is_varargs) => { 180 TypeRef::Fn(params, is_varargs) => {
181 let substs = Substitution(params.iter().map(|tr| self.lower_ty(tr)).collect()); 181 let substs =
182 Substitution::from_iter(&Interner, params.iter().map(|tr| self.lower_ty(tr)));
182 TyKind::Function(FnPointer { 183 TyKind::Function(FnPointer {
183 num_args: substs.len() - 1, 184 num_args: substs.len(&Interner) - 1,
184 sig: FnSig { abi: (), safety: Safety::Safe, variadic: *is_varargs }, 185 sig: FnSig { abi: (), safety: Safety::Safe, variadic: *is_varargs },
185 substs, 186 substs,
186 }) 187 })
@@ -625,7 +626,7 @@ impl<'a> TyLoweringContext<'a> {
625 626
626 for default_ty in defaults.iter().skip(substs.len()) { 627 for default_ty in defaults.iter().skip(substs.len()) {
627 // each default can depend on the previous parameters 628 // each default can depend on the previous parameters
628 let substs_so_far = Substitution(substs.clone().into()); 629 let substs_so_far = Substitution::from_iter(&Interner, substs.clone());
629 substs.push(default_ty.clone().subst(&substs_so_far)); 630 substs.push(default_ty.clone().subst(&substs_so_far));
630 } 631 }
631 } 632 }
@@ -638,7 +639,7 @@ impl<'a> TyLoweringContext<'a> {
638 } 639 }
639 assert_eq!(substs.len(), total_len); 640 assert_eq!(substs.len(), total_len);
640 641
641 Substitution(substs.into()) 642 Substitution::from_iter(&Interner, substs)
642 } 643 }
643 644
644 fn lower_trait_ref_from_path( 645 fn lower_trait_ref_from_path(
@@ -1062,7 +1063,7 @@ fn type_for_fn(db: &dyn HirDatabase, def: FunctionId) -> Binders<Ty> {
1062 let generics = generics(db.upcast(), def.into()); 1063 let generics = generics(db.upcast(), def.into());
1063 let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST); 1064 let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST);
1064 Binders::new( 1065 Binders::new(
1065 substs.len(), 1066 substs.len(&Interner),
1066 TyKind::FnDef(CallableDefId::FunctionId(def).to_chalk(db), substs).intern(&Interner), 1067 TyKind::FnDef(CallableDefId::FunctionId(def).to_chalk(db), substs).intern(&Interner),
1067 ) 1068 )
1068} 1069}
@@ -1107,7 +1108,7 @@ fn type_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> Binders<T
1107 let generics = generics(db.upcast(), def.into()); 1108 let generics = generics(db.upcast(), def.into());
1108 let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST); 1109 let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST);
1109 Binders::new( 1110 Binders::new(
1110 substs.len(), 1111 substs.len(&Interner),
1111 TyKind::FnDef(CallableDefId::StructId(def).to_chalk(db), substs).intern(&Interner), 1112 TyKind::FnDef(CallableDefId::StructId(def).to_chalk(db), substs).intern(&Interner),
1112 ) 1113 )
1113} 1114}
@@ -1134,7 +1135,7 @@ fn type_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) -
1134 let generics = generics(db.upcast(), def.parent.into()); 1135 let generics = generics(db.upcast(), def.parent.into());
1135 let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST); 1136 let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST);
1136 Binders::new( 1137 Binders::new(
1137 substs.len(), 1138 substs.len(&Interner),
1138 TyKind::FnDef(CallableDefId::EnumVariantId(def).to_chalk(db), substs).intern(&Interner), 1139 TyKind::FnDef(CallableDefId::EnumVariantId(def).to_chalk(db), substs).intern(&Interner),
1139 ) 1140 )
1140} 1141}
@@ -1142,7 +1143,7 @@ fn type_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) -
1142fn type_for_adt(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> { 1143fn type_for_adt(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> {
1143 let generics = generics(db.upcast(), adt.into()); 1144 let generics = generics(db.upcast(), adt.into());
1144 let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST); 1145 let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST);
1145 Binders::new(substs.len(), Ty::adt_ty(adt, substs)) 1146 Binders::new(substs.len(&Interner), Ty::adt_ty(adt, substs))
1146} 1147}
1147 1148
1148fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> { 1149fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> {