diff options
Diffstat (limited to 'crates/hir_ty/src/method_resolution.rs')
-rw-r--r-- | crates/hir_ty/src/method_resolution.rs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index 338851fa8..0e4a620b6 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs | |||
@@ -19,10 +19,9 @@ use crate::{ | |||
19 | db::HirDatabase, | 19 | db::HirDatabase, |
20 | from_foreign_def_id, | 20 | from_foreign_def_id, |
21 | primitive::{self, FloatTy, IntTy, UintTy}, | 21 | primitive::{self, FloatTy, IntTy, UintTy}, |
22 | to_chalk_trait_id, | ||
23 | utils::all_super_traits, | 22 | utils::all_super_traits, |
24 | AdtId, Canonical, CanonicalVarKinds, DebruijnIndex, FnPointer, FnSig, ForeignDefId, | 23 | AdtId, Canonical, CanonicalVarKinds, DebruijnIndex, FnPointer, FnSig, ForeignDefId, |
25 | InEnvironment, Interner, Scalar, Substitution, TraitEnvironment, TraitRef, Ty, TyKind, | 24 | InEnvironment, Interner, Scalar, Substitution, TraitEnvironment, Ty, TyBuilder, TyKind, |
26 | TypeWalk, | 25 | TypeWalk, |
27 | }; | 26 | }; |
28 | 27 | ||
@@ -675,7 +674,7 @@ fn is_valid_candidate( | |||
675 | } | 674 | } |
676 | } | 675 | } |
677 | if let Some(receiver_ty) = receiver_ty { | 676 | if let Some(receiver_ty) = receiver_ty { |
678 | if !data.has_self_param { | 677 | if !data.has_self_param() { |
679 | return false; | 678 | return false; |
680 | } | 679 | } |
681 | let transformed_receiver_ty = match transform_receiver_ty(db, m, self_ty) { | 680 | let transformed_receiver_ty = match transform_receiver_ty(db, m, self_ty) { |
@@ -710,7 +709,7 @@ pub(crate) fn inherent_impl_substs( | |||
710 | ) -> Option<Substitution> { | 709 | ) -> Option<Substitution> { |
711 | // we create a var for each type parameter of the impl; we need to keep in | 710 | // we create a var for each type parameter of the impl; we need to keep in |
712 | // mind here that `self_ty` might have vars of its own | 711 | // mind here that `self_ty` might have vars of its own |
713 | let vars = Substitution::build_for_def(db, impl_id) | 712 | let vars = TyBuilder::subst_for_def(db, impl_id) |
714 | .fill_with_bound_vars(DebruijnIndex::INNERMOST, self_ty.binders.len(&Interner)) | 713 | .fill_with_bound_vars(DebruijnIndex::INNERMOST, self_ty.binders.len(&Interner)) |
715 | .build(); | 714 | .build(); |
716 | let self_ty_with_vars = db.impl_self_ty(impl_id).subst(&vars); | 715 | let self_ty_with_vars = db.impl_self_ty(impl_id).subst(&vars); |
@@ -761,13 +760,13 @@ fn transform_receiver_ty( | |||
761 | self_ty: &Canonical<Ty>, | 760 | self_ty: &Canonical<Ty>, |
762 | ) -> Option<Ty> { | 761 | ) -> Option<Ty> { |
763 | let substs = match function_id.lookup(db.upcast()).container { | 762 | let substs = match function_id.lookup(db.upcast()).container { |
764 | AssocContainerId::TraitId(_) => Substitution::build_for_def(db, function_id) | 763 | AssocContainerId::TraitId(_) => TyBuilder::subst_for_def(db, function_id) |
765 | .push(self_ty.value.clone()) | 764 | .push(self_ty.value.clone()) |
766 | .fill_with_unknown() | 765 | .fill_with_unknown() |
767 | .build(), | 766 | .build(), |
768 | AssocContainerId::ImplId(impl_id) => { | 767 | AssocContainerId::ImplId(impl_id) => { |
769 | let impl_substs = inherent_impl_substs(db, impl_id, &self_ty)?; | 768 | let impl_substs = inherent_impl_substs(db, impl_id, &self_ty)?; |
770 | Substitution::build_for_def(db, function_id) | 769 | TyBuilder::subst_for_def(db, function_id) |
771 | .use_parent_substs(&impl_substs) | 770 | .use_parent_substs(&impl_substs) |
772 | .fill_with_unknown() | 771 | .fill_with_unknown() |
773 | .build() | 772 | .build() |
@@ -801,7 +800,7 @@ pub fn implements_trait_unique( | |||
801 | let goal = generic_implements_goal(db, env, trait_, ty.clone()); | 800 | let goal = generic_implements_goal(db, env, trait_, ty.clone()); |
802 | let solution = db.trait_solve(krate, goal); | 801 | let solution = db.trait_solve(krate, goal); |
803 | 802 | ||
804 | matches!(solution, Some(crate::traits::Solution::Unique(_))) | 803 | matches!(solution, Some(crate::Solution::Unique(_))) |
805 | } | 804 | } |
806 | 805 | ||
807 | /// This creates Substs for a trait with the given Self type and type variables | 806 | /// This creates Substs for a trait with the given Self type and type variables |
@@ -813,7 +812,7 @@ fn generic_implements_goal( | |||
813 | self_ty: Canonical<Ty>, | 812 | self_ty: Canonical<Ty>, |
814 | ) -> Canonical<InEnvironment<super::DomainGoal>> { | 813 | ) -> Canonical<InEnvironment<super::DomainGoal>> { |
815 | let mut kinds = self_ty.binders.interned().to_vec(); | 814 | let mut kinds = self_ty.binders.interned().to_vec(); |
816 | let substs = super::Substitution::build_for_def(db, trait_) | 815 | let trait_ref = TyBuilder::trait_ref(db, trait_) |
817 | .push(self_ty.value) | 816 | .push(self_ty.value) |
818 | .fill_with_bound_vars(DebruijnIndex::INNERMOST, kinds.len()) | 817 | .fill_with_bound_vars(DebruijnIndex::INNERMOST, kinds.len()) |
819 | .build(); | 818 | .build(); |
@@ -822,9 +821,8 @@ fn generic_implements_goal( | |||
822 | chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General), | 821 | chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General), |
823 | UniverseIndex::ROOT, | 822 | UniverseIndex::ROOT, |
824 | )) | 823 | )) |
825 | .take(substs.len(&Interner) - 1), | 824 | .take(trait_ref.substitution.len(&Interner) - 1), |
826 | ); | 825 | ); |
827 | let trait_ref = TraitRef { trait_id: to_chalk_trait_id(trait_), substitution: substs }; | ||
828 | let obligation = trait_ref.cast(&Interner); | 826 | let obligation = trait_ref.cast(&Interner); |
829 | Canonical { | 827 | Canonical { |
830 | binders: CanonicalVarKinds::from_iter(&Interner, kinds), | 828 | binders: CanonicalVarKinds::from_iter(&Interner, kinds), |