aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/lower.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/lower.rs')
-rw-r--r--crates/hir_ty/src/lower.rs46
1 files changed, 25 insertions, 21 deletions
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 6ab757bfc..462882b2b 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -35,7 +35,7 @@ use crate::{
35 }, 35 },
36 AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, GenericPredicate, 36 AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, GenericPredicate,
37 ImplTraitId, OpaqueTy, PolyFnSig, ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, 37 ImplTraitId, OpaqueTy, PolyFnSig, ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait,
38 ReturnTypeImplTraits, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, 38 ReturnTypeImplTraits, Substitution, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk,
39}; 39};
40 40
41#[derive(Debug)] 41#[derive(Debug)]
@@ -151,7 +151,7 @@ impl<'a> TyLoweringContext<'a> {
151 TypeRef::Never => TyKind::Never.intern(&Interner), 151 TypeRef::Never => TyKind::Never.intern(&Interner),
152 TypeRef::Tuple(inner) => { 152 TypeRef::Tuple(inner) => {
153 let inner_tys = inner.iter().map(|tr| self.lower_ty(tr)); 153 let inner_tys = inner.iter().map(|tr| self.lower_ty(tr));
154 TyKind::Tuple(inner_tys.len(), Substs::from_iter(&Interner, inner_tys)) 154 TyKind::Tuple(inner_tys.len(), Substitution::from_iter(&Interner, inner_tys))
155 .intern(&Interner) 155 .intern(&Interner)
156 } 156 }
157 TypeRef::Path(path) => { 157 TypeRef::Path(path) => {
@@ -177,7 +177,7 @@ impl<'a> TyLoweringContext<'a> {
177 } 177 }
178 TypeRef::Placeholder => TyKind::Unknown.intern(&Interner), 178 TypeRef::Placeholder => TyKind::Unknown.intern(&Interner),
179 TypeRef::Fn(params, is_varargs) => { 179 TypeRef::Fn(params, is_varargs) => {
180 let substs = Substs(params.iter().map(|tr| self.lower_ty(tr)).collect()); 180 let substs = Substitution(params.iter().map(|tr| self.lower_ty(tr)).collect());
181 TyKind::Function(FnPointer { 181 TyKind::Function(FnPointer {
182 num_args: substs.len() - 1, 182 num_args: substs.len() - 1,
183 sig: FnSig { abi: (), safety: Safety::Safe, variadic: *is_varargs }, 183 sig: FnSig { abi: (), safety: Safety::Safe, variadic: *is_varargs },
@@ -228,7 +228,7 @@ impl<'a> TyLoweringContext<'a> {
228 let impl_trait_id = ImplTraitId::ReturnTypeImplTrait(func, idx); 228 let impl_trait_id = ImplTraitId::ReturnTypeImplTrait(func, idx);
229 let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into(); 229 let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into();
230 let generics = generics(self.db.upcast(), func.into()); 230 let generics = generics(self.db.upcast(), func.into());
231 let parameters = Substs::bound_vars(&generics, self.in_binders); 231 let parameters = Substitution::bound_vars(&generics, self.in_binders);
232 TyKind::Alias(AliasTy::Opaque(OpaqueTy { 232 TyKind::Alias(AliasTy::Opaque(OpaqueTy {
233 opaque_ty_id, 233 opaque_ty_id,
234 substitution: parameters, 234 substitution: parameters,
@@ -398,10 +398,10 @@ impl<'a> TyLoweringContext<'a> {
398 let generics = generics(self.db.upcast(), impl_id.into()); 398 let generics = generics(self.db.upcast(), impl_id.into());
399 let substs = match self.type_param_mode { 399 let substs = match self.type_param_mode {
400 TypeParamLoweringMode::Placeholder => { 400 TypeParamLoweringMode::Placeholder => {
401 Substs::type_params_for_generics(self.db, &generics) 401 Substitution::type_params_for_generics(self.db, &generics)
402 } 402 }
403 TypeParamLoweringMode::Variable => { 403 TypeParamLoweringMode::Variable => {
404 Substs::bound_vars(&generics, self.in_binders) 404 Substitution::bound_vars(&generics, self.in_binders)
405 } 405 }
406 }; 406 };
407 self.db.impl_self_ty(impl_id).subst(&substs) 407 self.db.impl_self_ty(impl_id).subst(&substs)
@@ -410,10 +410,10 @@ impl<'a> TyLoweringContext<'a> {
410 let generics = generics(self.db.upcast(), adt.into()); 410 let generics = generics(self.db.upcast(), adt.into());
411 let substs = match self.type_param_mode { 411 let substs = match self.type_param_mode {
412 TypeParamLoweringMode::Placeholder => { 412 TypeParamLoweringMode::Placeholder => {
413 Substs::type_params_for_generics(self.db, &generics) 413 Substitution::type_params_for_generics(self.db, &generics)
414 } 414 }
415 TypeParamLoweringMode::Variable => { 415 TypeParamLoweringMode::Variable => {
416 Substs::bound_vars(&generics, self.in_binders) 416 Substitution::bound_vars(&generics, self.in_binders)
417 } 417 }
418 }; 418 };
419 self.db.ty(adt.into()).subst(&substs) 419 self.db.ty(adt.into()).subst(&substs)
@@ -464,7 +464,7 @@ impl<'a> TyLoweringContext<'a> {
464 TypeParamLoweringMode::Placeholder => { 464 TypeParamLoweringMode::Placeholder => {
465 // if we're lowering to placeholders, we have to put 465 // if we're lowering to placeholders, we have to put
466 // them in now 466 // them in now
467 let s = Substs::type_params( 467 let s = Substitution::type_params(
468 self.db, 468 self.db,
469 self.resolver.generic_def().expect( 469 self.resolver.generic_def().expect(
470 "there should be generics if there's a generic param", 470 "there should be generics if there's a generic param",
@@ -522,7 +522,7 @@ impl<'a> TyLoweringContext<'a> {
522 // special-case enum variants 522 // special-case enum variants
523 resolved: ValueTyDefId, 523 resolved: ValueTyDefId,
524 infer_args: bool, 524 infer_args: bool,
525 ) -> Substs { 525 ) -> Substitution {
526 let last = path.segments().last().expect("path should have at least one segment"); 526 let last = path.segments().last().expect("path should have at least one segment");
527 let (segment, generic_def) = match resolved { 527 let (segment, generic_def) = match resolved {
528 ValueTyDefId::FunctionId(it) => (last, Some(it.into())), 528 ValueTyDefId::FunctionId(it) => (last, Some(it.into())),
@@ -553,7 +553,7 @@ impl<'a> TyLoweringContext<'a> {
553 segment: PathSegment<'_>, 553 segment: PathSegment<'_>,
554 def_generic: Option<GenericDefId>, 554 def_generic: Option<GenericDefId>,
555 infer_args: bool, 555 infer_args: bool,
556 ) -> Substs { 556 ) -> Substitution {
557 let mut substs = Vec::new(); 557 let mut substs = Vec::new();
558 let def_generics = def_generic.map(|def| generics(self.db.upcast(), def)); 558 let def_generics = def_generic.map(|def| generics(self.db.upcast(), def));
559 559
@@ -601,7 +601,7 @@ impl<'a> TyLoweringContext<'a> {
601 601
602 for default_ty in defaults.iter().skip(substs.len()) { 602 for default_ty in defaults.iter().skip(substs.len()) {
603 // each default can depend on the previous parameters 603 // each default can depend on the previous parameters
604 let substs_so_far = Substs(substs.clone().into()); 604 let substs_so_far = Substitution(substs.clone().into());
605 substs.push(default_ty.clone().subst(&substs_so_far)); 605 substs.push(default_ty.clone().subst(&substs_so_far));
606 } 606 }
607 } 607 }
@@ -614,7 +614,7 @@ impl<'a> TyLoweringContext<'a> {
614 } 614 }
615 assert_eq!(substs.len(), total_len); 615 assert_eq!(substs.len(), total_len);
616 616
617 Substs(substs.into()) 617 Substitution(substs.into())
618 } 618 }
619 619
620 fn lower_trait_ref_from_path( 620 fn lower_trait_ref_from_path(
@@ -656,7 +656,11 @@ impl<'a> TyLoweringContext<'a> {
656 self.lower_trait_ref_from_path(path, explicit_self_ty) 656 self.lower_trait_ref_from_path(path, explicit_self_ty)
657 } 657 }
658 658
659 fn trait_ref_substs_from_path(&self, segment: PathSegment<'_>, resolved: TraitId) -> Substs { 659 fn trait_ref_substs_from_path(
660 &self,
661 segment: PathSegment<'_>,
662 resolved: TraitId,
663 ) -> Substitution {
660 self.substs_from_path_segment(segment, Some(resolved.into()), false) 664 self.substs_from_path_segment(segment, Some(resolved.into()), false)
661 } 665 }
662 666
@@ -817,7 +821,7 @@ pub fn associated_type_shorthand_candidates<R>(
817 { 821 {
818 let trait_ref = TraitRef { 822 let trait_ref = TraitRef {
819 trait_: trait_id, 823 trait_: trait_id,
820 substs: Substs::bound_vars(&generics, DebruijnIndex::INNERMOST), 824 substs: Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST),
821 }; 825 };
822 traits_.push(trait_ref); 826 traits_.push(trait_ref);
823 } 827 }
@@ -945,7 +949,7 @@ pub(crate) fn trait_environment_query(
945 // function default implementations (and hypothetical code 949 // function default implementations (and hypothetical code
946 // inside consts or type aliases) 950 // inside consts or type aliases)
947 cov_mark::hit!(trait_self_implements_self); 951 cov_mark::hit!(trait_self_implements_self);
948 let substs = Substs::type_params(db, trait_id); 952 let substs = Substitution::type_params(db, trait_id);
949 let trait_ref = TraitRef { trait_: trait_id, substs }; 953 let trait_ref = TraitRef { trait_: trait_id, substs };
950 let pred = GenericPredicate::Implemented(trait_ref); 954 let pred = GenericPredicate::Implemented(trait_ref);
951 let program_clause: chalk_ir::ProgramClause<Interner> = 955 let program_clause: chalk_ir::ProgramClause<Interner> =
@@ -1033,7 +1037,7 @@ fn fn_sig_for_fn(db: &dyn HirDatabase, def: FunctionId) -> PolyFnSig {
1033/// function body. 1037/// function body.
1034fn type_for_fn(db: &dyn HirDatabase, def: FunctionId) -> Binders<Ty> { 1038fn type_for_fn(db: &dyn HirDatabase, def: FunctionId) -> Binders<Ty> {
1035 let generics = generics(db.upcast(), def.into()); 1039 let generics = generics(db.upcast(), def.into());
1036 let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); 1040 let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST);
1037 Binders::new( 1041 Binders::new(
1038 substs.len(), 1042 substs.len(),
1039 TyKind::FnDef(CallableDefId::FunctionId(def).to_chalk(db), substs).intern(&Interner), 1043 TyKind::FnDef(CallableDefId::FunctionId(def).to_chalk(db), substs).intern(&Interner),
@@ -1078,7 +1082,7 @@ fn type_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> Binders<T
1078 return type_for_adt(db, def.into()); 1082 return type_for_adt(db, def.into());
1079 } 1083 }
1080 let generics = generics(db.upcast(), def.into()); 1084 let generics = generics(db.upcast(), def.into());
1081 let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); 1085 let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST);
1082 Binders::new( 1086 Binders::new(
1083 substs.len(), 1087 substs.len(),
1084 TyKind::FnDef(CallableDefId::StructId(def).to_chalk(db), substs).intern(&Interner), 1088 TyKind::FnDef(CallableDefId::StructId(def).to_chalk(db), substs).intern(&Interner),
@@ -1105,7 +1109,7 @@ fn type_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) -
1105 return type_for_adt(db, def.parent.into()); 1109 return type_for_adt(db, def.parent.into());
1106 } 1110 }
1107 let generics = generics(db.upcast(), def.parent.into()); 1111 let generics = generics(db.upcast(), def.parent.into());
1108 let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); 1112 let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST);
1109 Binders::new( 1113 Binders::new(
1110 substs.len(), 1114 substs.len(),
1111 TyKind::FnDef(CallableDefId::EnumVariantId(def).to_chalk(db), substs).intern(&Interner), 1115 TyKind::FnDef(CallableDefId::EnumVariantId(def).to_chalk(db), substs).intern(&Interner),
@@ -1114,7 +1118,7 @@ fn type_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) -
1114 1118
1115fn type_for_adt(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> { 1119fn type_for_adt(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> {
1116 let generics = generics(db.upcast(), adt.into()); 1120 let generics = generics(db.upcast(), adt.into());
1117 let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); 1121 let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST);
1118 Binders::new(substs.len(), Ty::adt_ty(adt, substs)) 1122 Binders::new(substs.len(), Ty::adt_ty(adt, substs))
1119} 1123}
1120 1124
@@ -1126,7 +1130,7 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> {
1126 if db.type_alias_data(t).is_extern { 1130 if db.type_alias_data(t).is_extern {
1127 Binders::new(0, TyKind::ForeignType(crate::to_foreign_def_id(t)).intern(&Interner)) 1131 Binders::new(0, TyKind::ForeignType(crate::to_foreign_def_id(t)).intern(&Interner))
1128 } else { 1132 } else {
1129 let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); 1133 let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST);
1130 let type_ref = &db.type_alias_data(t).type_ref; 1134 let type_ref = &db.type_alias_data(t).type_ref;
1131 let inner = ctx.lower_ty(type_ref.as_ref().unwrap_or(&TypeRef::Error)); 1135 let inner = ctx.lower_ty(type_ref.as_ref().unwrap_or(&TypeRef::Error));
1132 Binders::new(substs.len(), inner) 1136 Binders::new(substs.len(), inner)