aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/infer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/infer.rs')
-rw-r--r--crates/hir_ty/src/infer.rs15
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
58mod unify; 58pub mod unify;
59mod path; 59mod path;
60mod expr; 60mod expr;
61mod pat; 61mod 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
81pub(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)]
82enum ExprOrPatId { 95enum ExprOrPatId {
83 ExprId(ExprId), 96 ExprId(ExprId),