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.rs20
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
52pub use crate::traits::chalk::Interner; 52pub use crate::traits::chalk::Interner;
53 53
54pub type ForeignDefId = chalk_ir::ForeignDefId<Interner>;
55
54#[derive(Clone, PartialEq, Eq, Debug, Hash)] 56#[derive(Clone, PartialEq, Eq, Debug, Hash)]
55pub enum Lifetime { 57pub 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 {
1116pub(crate) struct ReturnTypeImplTrait { 1120pub(crate) struct ReturnTypeImplTrait {
1117 pub(crate) bounds: Binders<Vec<GenericPredicate>>, 1121 pub(crate) bounds: Binders<Vec<GenericPredicate>>,
1118} 1122}
1123
1124pub(crate) fn to_foreign_def_id(id: TypeAliasId) -> chalk_ir::ForeignDefId<Interner> {
1125 chalk_ir::ForeignDefId(salsa::InternKey::as_intern_id(&id))
1126}
1127
1128pub(crate) fn from_foreign_def_id(id: chalk_ir::ForeignDefId<Interner>) -> TypeAliasId {
1129 salsa::InternKey::from_intern_id(id.0)
1130}