mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Add and start using TraitRef and ProjectionTy builders
This commit is contained in:
parent
2ead65190e
commit
cd227f581e
6 changed files with 48 additions and 39 deletions
|
@ -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<Type> {
|
||||
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),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue