diff options
Diffstat (limited to 'crates/hir_ty/src/lib.rs')
-rw-r--r-- | crates/hir_ty/src/lib.rs | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 94cbb21ca..5752ddc4e 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs | |||
@@ -52,6 +52,7 @@ pub use chalk_ir::{AdtId, BoundVar, DebruijnIndex, Mutability, Scalar, TyVariabl | |||
52 | pub use crate::traits::chalk::Interner; | 52 | pub use crate::traits::chalk::Interner; |
53 | 53 | ||
54 | pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>; | 54 | pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>; |
55 | pub type AssocTypeId = chalk_ir::AssocTypeId<Interner>; | ||
55 | 56 | ||
56 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 57 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
57 | pub enum Lifetime { | 58 | pub enum Lifetime { |
@@ -70,7 +71,7 @@ pub struct OpaqueTy { | |||
70 | /// trait and all its parameters are fully known. | 71 | /// trait and all its parameters are fully known. |
71 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 72 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
72 | pub struct ProjectionTy { | 73 | pub struct ProjectionTy { |
73 | pub associated_ty: TypeAliasId, | 74 | pub associated_ty: AssocTypeId, |
74 | pub parameters: Substs, | 75 | pub parameters: Substs, |
75 | } | 76 | } |
76 | 77 | ||
@@ -80,7 +81,7 @@ impl ProjectionTy { | |||
80 | } | 81 | } |
81 | 82 | ||
82 | fn trait_(&self, db: &dyn HirDatabase) -> TraitId { | 83 | fn trait_(&self, db: &dyn HirDatabase) -> TraitId { |
83 | match self.associated_ty.lookup(db.upcast()).container { | 84 | match from_assoc_type_id(self.associated_ty).lookup(db.upcast()).container { |
84 | AssocContainerId::TraitId(it) => it, | 85 | AssocContainerId::TraitId(it) => it, |
85 | _ => panic!("projection ty without parent trait"), | 86 | _ => panic!("projection ty without parent trait"), |
86 | } | 87 | } |
@@ -141,7 +142,7 @@ pub enum TyKind { | |||
141 | /// when we have tried to normalize a projection like `T::Item` but | 142 | /// when we have tried to normalize a projection like `T::Item` but |
142 | /// couldn't find a better representation. In that case, we generate | 143 | /// couldn't find a better representation. In that case, we generate |
143 | /// an **application type** like `(Iterator::Item)<T>`. | 144 | /// an **application type** like `(Iterator::Item)<T>`. |
144 | AssociatedType(TypeAliasId, Substs), | 145 | AssociatedType(AssocTypeId, Substs), |
145 | 146 | ||
146 | /// a scalar type like `bool` or `u32` | 147 | /// a scalar type like `bool` or `u32` |
147 | Scalar(Scalar), | 148 | Scalar(Scalar), |
@@ -706,7 +707,7 @@ impl Ty { | |||
706 | match *self.interned(&Interner) { | 707 | match *self.interned(&Interner) { |
707 | TyKind::Adt(AdtId(adt), ..) => Some(adt.into()), | 708 | TyKind::Adt(AdtId(adt), ..) => Some(adt.into()), |
708 | TyKind::FnDef(callable, ..) => Some(callable.into()), | 709 | TyKind::FnDef(callable, ..) => Some(callable.into()), |
709 | TyKind::AssociatedType(type_alias, ..) => Some(type_alias.into()), | 710 | TyKind::AssociatedType(type_alias, ..) => Some(from_assoc_type_id(type_alias).into()), |
710 | TyKind::ForeignType(type_alias, ..) => Some(from_foreign_def_id(type_alias).into()), | 711 | TyKind::ForeignType(type_alias, ..) => Some(from_foreign_def_id(type_alias).into()), |
711 | _ => None, | 712 | _ => None, |
712 | } | 713 | } |
@@ -920,14 +921,15 @@ impl Ty { | |||
920 | 921 | ||
921 | pub fn associated_type_parent_trait(&self, db: &dyn HirDatabase) -> Option<TraitId> { | 922 | pub fn associated_type_parent_trait(&self, db: &dyn HirDatabase) -> Option<TraitId> { |
922 | match self.interned(&Interner) { | 923 | match self.interned(&Interner) { |
923 | TyKind::AssociatedType(type_alias_id, ..) => { | 924 | TyKind::AssociatedType(id, ..) => { |
924 | match type_alias_id.lookup(db.upcast()).container { | 925 | match from_assoc_type_id(*id).lookup(db.upcast()).container { |
925 | AssocContainerId::TraitId(trait_id) => Some(trait_id), | 926 | AssocContainerId::TraitId(trait_id) => Some(trait_id), |
926 | _ => None, | 927 | _ => None, |
927 | } | 928 | } |
928 | } | 929 | } |
929 | TyKind::Alias(AliasTy::Projection(projection_ty)) => { | 930 | TyKind::Alias(AliasTy::Projection(projection_ty)) => { |
930 | match projection_ty.associated_ty.lookup(db.upcast()).container { | 931 | match from_assoc_type_id(projection_ty.associated_ty).lookup(db.upcast()).container |
932 | { | ||
931 | AssocContainerId::TraitId(trait_id) => Some(trait_id), | 933 | AssocContainerId::TraitId(trait_id) => Some(trait_id), |
932 | _ => None, | 934 | _ => None, |
933 | } | 935 | } |
@@ -1121,10 +1123,18 @@ pub(crate) struct ReturnTypeImplTrait { | |||
1121 | pub(crate) bounds: Binders<Vec<GenericPredicate>>, | 1123 | pub(crate) bounds: Binders<Vec<GenericPredicate>>, |
1122 | } | 1124 | } |
1123 | 1125 | ||
1124 | pub(crate) fn to_foreign_def_id(id: TypeAliasId) -> chalk_ir::ForeignDefId<Interner> { | 1126 | pub fn to_foreign_def_id(id: TypeAliasId) -> ForeignDefId { |
1125 | chalk_ir::ForeignDefId(salsa::InternKey::as_intern_id(&id)) | 1127 | chalk_ir::ForeignDefId(salsa::InternKey::as_intern_id(&id)) |
1126 | } | 1128 | } |
1127 | 1129 | ||
1128 | pub(crate) fn from_foreign_def_id(id: chalk_ir::ForeignDefId<Interner>) -> TypeAliasId { | 1130 | pub fn from_foreign_def_id(id: ForeignDefId) -> TypeAliasId { |
1131 | salsa::InternKey::from_intern_id(id.0) | ||
1132 | } | ||
1133 | |||
1134 | pub fn to_assoc_type_id(id: TypeAliasId) -> AssocTypeId { | ||
1135 | chalk_ir::AssocTypeId(salsa::InternKey::as_intern_id(&id)) | ||
1136 | } | ||
1137 | |||
1138 | pub fn from_assoc_type_id(id: AssocTypeId) -> TypeAliasId { | ||
1129 | salsa::InternKey::from_intern_id(id.0) | 1139 | salsa::InternKey::from_intern_id(id.0) |
1130 | } | 1140 | } |