diff options
author | Florian Diebold <[email protected]> | 2021-03-13 16:23:19 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2021-03-13 16:56:48 +0000 |
commit | dfafcd926a4cc9b09aba0eb3cc5275a4abe633b9 (patch) | |
tree | cfb4000f57a35b2dc2fdab78a5b422fc3af3667e /crates/hir_ty/src/lib.rs | |
parent | d4533785698d439417bc5474fecd62a7f1707368 (diff) |
Use chalk_ir::ForeignDefId
Diffstat (limited to 'crates/hir_ty/src/lib.rs')
-rw-r--r-- | crates/hir_ty/src/lib.rs | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 2309db492..94cbb21ca 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs | |||
@@ -51,6 +51,8 @@ pub use chalk_ir::{AdtId, BoundVar, DebruijnIndex, Mutability, Scalar, TyVariabl | |||
51 | 51 | ||
52 | pub use crate::traits::chalk::Interner; | 52 | pub use crate::traits::chalk::Interner; |
53 | 53 | ||
54 | pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>; | ||
55 | |||
54 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 56 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
55 | pub enum Lifetime { | 57 | pub enum Lifetime { |
56 | Parameter(LifetimeParamId), | 58 | Parameter(LifetimeParamId), |
@@ -194,7 +196,7 @@ pub enum TyKind { | |||
194 | Closure(DefWithBodyId, ExprId, Substs), | 196 | Closure(DefWithBodyId, ExprId, Substs), |
195 | 197 | ||
196 | /// Represents a foreign type declared in external blocks. | 198 | /// Represents a foreign type declared in external blocks. |
197 | ForeignType(TypeAliasId), | 199 | ForeignType(ForeignDefId), |
198 | 200 | ||
199 | /// A pointer to a function. Written as `fn() -> i32`. | 201 | /// A pointer to a function. Written as `fn() -> i32`. |
200 | /// | 202 | /// |
@@ -705,7 +707,7 @@ impl Ty { | |||
705 | TyKind::Adt(AdtId(adt), ..) => Some(adt.into()), | 707 | TyKind::Adt(AdtId(adt), ..) => Some(adt.into()), |
706 | TyKind::FnDef(callable, ..) => Some(callable.into()), | 708 | TyKind::FnDef(callable, ..) => Some(callable.into()), |
707 | TyKind::AssociatedType(type_alias, ..) => Some(type_alias.into()), | 709 | TyKind::AssociatedType(type_alias, ..) => Some(type_alias.into()), |
708 | TyKind::ForeignType(type_alias, ..) => Some(type_alias.into()), | 710 | TyKind::ForeignType(type_alias, ..) => Some(from_foreign_def_id(type_alias).into()), |
709 | _ => None, | 711 | _ => None, |
710 | } | 712 | } |
711 | } | 713 | } |
@@ -724,8 +726,10 @@ impl Ty { | |||
724 | (TyKind::Slice(_), TyKind::Slice(_)) | (TyKind::Array(_), TyKind::Array(_)) => true, | 726 | (TyKind::Slice(_), TyKind::Slice(_)) | (TyKind::Array(_), TyKind::Array(_)) => true, |
725 | (TyKind::FnDef(def_id, ..), TyKind::FnDef(def_id2, ..)) => def_id == def_id2, | 727 | (TyKind::FnDef(def_id, ..), TyKind::FnDef(def_id2, ..)) => def_id == def_id2, |
726 | (TyKind::OpaqueType(ty_id, ..), TyKind::OpaqueType(ty_id2, ..)) => ty_id == ty_id2, | 728 | (TyKind::OpaqueType(ty_id, ..), TyKind::OpaqueType(ty_id2, ..)) => ty_id == ty_id2, |
727 | (TyKind::AssociatedType(ty_id, ..), TyKind::AssociatedType(ty_id2, ..)) | 729 | (TyKind::AssociatedType(ty_id, ..), TyKind::AssociatedType(ty_id2, ..)) => { |
728 | | (TyKind::ForeignType(ty_id, ..), TyKind::ForeignType(ty_id2, ..)) => ty_id == ty_id2, | 730 | ty_id == ty_id2 |
731 | } | ||
732 | (TyKind::ForeignType(ty_id, ..), TyKind::ForeignType(ty_id2, ..)) => ty_id == ty_id2, | ||
729 | (TyKind::Closure(def, expr, _), TyKind::Closure(def2, expr2, _)) => { | 733 | (TyKind::Closure(def, expr, _), TyKind::Closure(def2, expr2, _)) => { |
730 | expr == expr2 && def == def2 | 734 | expr == expr2 && def == def2 |
731 | } | 735 | } |
@@ -1116,3 +1120,11 @@ pub struct ReturnTypeImplTraits { | |||
1116 | pub(crate) struct ReturnTypeImplTrait { | 1120 | pub(crate) struct ReturnTypeImplTrait { |
1117 | pub(crate) bounds: Binders<Vec<GenericPredicate>>, | 1121 | pub(crate) bounds: Binders<Vec<GenericPredicate>>, |
1118 | } | 1122 | } |
1123 | |||
1124 | pub(crate) fn to_foreign_def_id(id: TypeAliasId) -> chalk_ir::ForeignDefId<Interner> { | ||
1125 | chalk_ir::ForeignDefId(salsa::InternKey::as_intern_id(&id)) | ||
1126 | } | ||
1127 | |||
1128 | pub(crate) fn from_foreign_def_id(id: chalk_ir::ForeignDefId<Interner>) -> TypeAliasId { | ||
1129 | salsa::InternKey::from_intern_id(id.0) | ||
1130 | } | ||