aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/lib.rs')
-rw-r--r--crates/hir_ty/src/lib.rs39
1 files changed, 27 insertions, 12 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 52b498ff7..3859dbfa1 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -58,6 +58,8 @@ pub type ClosureId = chalk_ir::ClosureId<Interner>;
58pub type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>; 58pub type OpaqueTyId = chalk_ir::OpaqueTyId<Interner>;
59pub type PlaceholderIndex = chalk_ir::PlaceholderIndex; 59pub type PlaceholderIndex = chalk_ir::PlaceholderIndex;
60 60
61pub type ChalkTraitId = chalk_ir::TraitId<Interner>;
62
61#[derive(Clone, PartialEq, Eq, Debug, Hash)] 63#[derive(Clone, PartialEq, Eq, Debug, Hash)]
62pub enum Lifetime { 64pub enum Lifetime {
63 Parameter(LifetimeParamId), 65 Parameter(LifetimeParamId),
@@ -81,7 +83,10 @@ pub struct ProjectionTy {
81 83
82impl ProjectionTy { 84impl ProjectionTy {
83 pub fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef { 85 pub fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef {
84 TraitRef { trait_: self.trait_(db), substs: self.substitution.clone() } 86 TraitRef {
87 trait_id: to_chalk_trait_id(self.trait_(db)),
88 substitution: self.substitution.clone(),
89 }
85 } 90 }
86 91
87 fn trait_(&self, db: &dyn HirDatabase) -> TraitId { 92 fn trait_(&self, db: &dyn HirDatabase) -> TraitId {
@@ -493,23 +498,25 @@ impl<T: TypeWalk> TypeWalk for Binders<T> {
493} 498}
494 499
495/// A trait with type parameters. This includes the `Self`, so this represents a concrete type implementing the trait. 500/// A trait with type parameters. This includes the `Self`, so this represents a concrete type implementing the trait.
496/// Name to be bikeshedded: TraitBound? TraitImplements?
497#[derive(Clone, PartialEq, Eq, Debug, Hash)] 501#[derive(Clone, PartialEq, Eq, Debug, Hash)]
498pub struct TraitRef { 502pub struct TraitRef {
499 /// FIXME name? 503 pub trait_id: ChalkTraitId,
500 pub trait_: TraitId, 504 pub substitution: Substitution,
501 pub substs: Substitution,
502} 505}
503 506
504impl TraitRef { 507impl TraitRef {
505 pub fn self_ty(&self) -> &Ty { 508 pub fn self_type_parameter(&self) -> &Ty {
506 &self.substs[0] 509 &self.substitution[0]
510 }
511
512 pub fn hir_trait_id(&self) -> TraitId {
513 from_chalk_trait_id(self.trait_id)
507 } 514 }
508} 515}
509 516
510impl TypeWalk for TraitRef { 517impl TypeWalk for TraitRef {
511 fn walk(&self, f: &mut impl FnMut(&Ty)) { 518 fn walk(&self, f: &mut impl FnMut(&Ty)) {
512 self.substs.walk(f); 519 self.substitution.walk(f);
513 } 520 }
514 521
515 fn walk_mut_binders( 522 fn walk_mut_binders(
@@ -517,7 +524,7 @@ impl TypeWalk for TraitRef {
517 f: &mut impl FnMut(&mut Ty, DebruijnIndex), 524 f: &mut impl FnMut(&mut Ty, DebruijnIndex),
518 binders: DebruijnIndex, 525 binders: DebruijnIndex,
519 ) { 526 ) {
520 self.substs.walk_mut_binders(f, binders); 527 self.substitution.walk_mut_binders(f, binders);
521 } 528 }
522} 529}
523 530
@@ -784,7 +791,7 @@ impl Ty {
784 791
785 /// If this is a `dyn Trait`, returns that trait. 792 /// If this is a `dyn Trait`, returns that trait.
786 pub fn dyn_trait(&self) -> Option<TraitId> { 793 pub fn dyn_trait(&self) -> Option<TraitId> {
787 self.dyn_trait_ref().map(|it| it.trait_) 794 self.dyn_trait_ref().map(|it| it.trait_id).map(from_chalk_trait_id)
788 } 795 }
789 796
790 fn builtin_deref(&self) -> Option<Ty> { 797 fn builtin_deref(&self) -> Option<Ty> {
@@ -868,8 +875,8 @@ impl Ty {
868 // Parameters will be walked outside, and projection predicate is not used. 875 // Parameters will be walked outside, and projection predicate is not used.
869 // So just provide the Future trait. 876 // So just provide the Future trait.
870 let impl_bound = GenericPredicate::Implemented(TraitRef { 877 let impl_bound = GenericPredicate::Implemented(TraitRef {
871 trait_: future_trait, 878 trait_id: to_chalk_trait_id(future_trait),
872 substs: Substitution::empty(), 879 substitution: Substitution::empty(),
873 }); 880 });
874 Some(vec![impl_bound]) 881 Some(vec![impl_bound])
875 } else { 882 } else {
@@ -1158,3 +1165,11 @@ pub fn to_placeholder_idx(db: &dyn HirDatabase, id: TypeParamId) -> PlaceholderI
1158 idx: salsa::InternKey::as_intern_id(&interned_id).as_usize(), 1165 idx: salsa::InternKey::as_intern_id(&interned_id).as_usize(),
1159 } 1166 }
1160} 1167}
1168
1169pub fn to_chalk_trait_id(id: TraitId) -> ChalkTraitId {
1170 chalk_ir::TraitId(salsa::InternKey::as_intern_id(&id))
1171}
1172
1173pub fn from_chalk_trait_id(id: ChalkTraitId) -> TraitId {
1174 salsa::InternKey::from_intern_id(id.0)
1175}