From cd227f581e0c20d6b9ee81a3982509a9f6b2f67f Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 3 Apr 2021 21:50:52 +0200 Subject: Add and start using TraitRef and ProjectionTy builders --- crates/hir/src/lib.rs | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'crates/hir') diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 682d49a21..15f46f720 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -55,11 +55,10 @@ use hir_ty::{ autoderef, could_unify, method_resolution::{self, TyFingerprint}, primitive::UintTy, - to_assoc_type_id, traits::{FnTrait, Solution, SolutionVariables}, AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, Cast, - DebruijnIndex, InEnvironment, Interner, ProjectionTy, QuantifiedWhereClause, Scalar, - Substitution, TraitEnvironment, Ty, TyBuilder, TyDefId, TyKind, TyVariableKind, WhereClause, + DebruijnIndex, InEnvironment, Interner, QuantifiedWhereClause, Scalar, Substitution, + TraitEnvironment, Ty, TyBuilder, TyDefId, TyKind, TyVariableKind, WhereClause, }; use itertools::Itertools; use rustc_hash::FxHashSet; @@ -1785,13 +1784,10 @@ impl Type { } pub fn impls_trait(&self, db: &dyn HirDatabase, trait_: Trait, args: &[Type]) -> bool { - let trait_ref = hir_ty::TraitRef { - trait_id: hir_ty::to_chalk_trait_id(trait_.id), - substitution: Substitution::build_for_def(db, trait_.id) - .push(self.ty.clone()) - .fill(args.iter().map(|t| t.ty.clone())) - .build(), - }; + let trait_ref = TyBuilder::trait_ref(db, trait_.id) + .push(self.ty.clone()) + .fill(args.iter().map(|t| t.ty.clone())) + .build(); let goal = Canonical { value: hir_ty::InEnvironment::new(self.env.env.clone(), trait_ref.cast(&Interner)), @@ -1804,11 +1800,10 @@ impl Type { pub fn normalize_trait_assoc_type( &self, db: &dyn HirDatabase, - trait_: Trait, args: &[Type], alias: TypeAlias, ) -> Option { - let subst = Substitution::build_for_def(db, trait_.id) + let projection = TyBuilder::assoc_type_projection(db, alias.id) .push(self.ty.clone()) .fill(args.iter().map(|t| t.ty.clone())) .build(); @@ -1816,10 +1811,7 @@ impl Type { InEnvironment::new( self.env.env.clone(), AliasEq { - alias: AliasTy::Projection(ProjectionTy { - associated_ty_id: to_assoc_type_id(alias.id), - substitution: subst, - }), + alias: AliasTy::Projection(projection), ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)) .intern(&Interner), } -- cgit v1.2.3