diff options
Diffstat (limited to 'crates/hir_ty/src/infer.rs')
-rw-r--r-- | crates/hir_ty/src/infer.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index 03b00b101..d461e077b 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs | |||
@@ -55,7 +55,7 @@ macro_rules! ty_app { | |||
55 | }; | 55 | }; |
56 | } | 56 | } |
57 | 57 | ||
58 | mod unify; | 58 | pub mod unify; |
59 | mod path; | 59 | mod path; |
60 | mod expr; | 60 | mod expr; |
61 | mod pat; | 61 | mod pat; |
@@ -78,6 +78,19 @@ pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<Infer | |||
78 | Arc::new(ctx.resolve_all()) | 78 | Arc::new(ctx.resolve_all()) |
79 | } | 79 | } |
80 | 80 | ||
81 | pub(crate) fn can_unify(db: &dyn HirDatabase, def: DefWithBodyId, ty1: Ty, ty2: Ty) -> bool { | ||
82 | let resolver = def.resolver(db.upcast()); | ||
83 | let mut ctx = InferenceContext::new(db, def, resolver); | ||
84 | |||
85 | let ty1 = ctx.canonicalizer().canonicalize_ty(ty1).value; | ||
86 | let ty2 = ctx.canonicalizer().canonicalize_ty(ty2).value; | ||
87 | let mut kinds = Vec::from(ty1.kinds.to_vec()); | ||
88 | kinds.extend_from_slice(ty2.kinds.as_ref()); | ||
89 | let tys = crate::Canonical::new((ty1.value, ty2.value), kinds); | ||
90 | |||
91 | unify(&tys).is_some() | ||
92 | } | ||
93 | |||
81 | #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] | 94 | #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] |
82 | enum ExprOrPatId { | 95 | enum ExprOrPatId { |
83 | ExprId(ExprId), | 96 | ExprId(ExprId), |