aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
diff options
context:
space:
mode:
authoradamrk <[email protected]>2020-08-22 19:11:37 +0100
committeradamrk <[email protected]>2020-08-30 11:34:32 +0100
commitc6ddb907144688ae77a6de3666159feef53638e1 (patch)
treea560689c0ff6a35b7ed6a6738c48524730a60263 /crates/hir_ty
parentac4b134c6be27642dbe915f32a41f9a21bd0c1c9 (diff)
Add references to fn args during completion
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/db.rs3
-rw-r--r--crates/hir_ty/src/infer.rs15
-rw-r--r--crates/hir_ty/src/lib.rs2
3 files changed, 18 insertions, 2 deletions
diff --git a/crates/hir_ty/src/db.rs b/crates/hir_ty/src/db.rs
index 25cf9eb7f..57e60c53b 100644
--- a/crates/hir_ty/src/db.rs
+++ b/crates/hir_ty/src/db.rs
@@ -26,6 +26,9 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
26 #[salsa::invoke(crate::infer::infer_query)] 26 #[salsa::invoke(crate::infer::infer_query)]
27 fn infer_query(&self, def: DefWithBodyId) -> Arc<InferenceResult>; 27 fn infer_query(&self, def: DefWithBodyId) -> Arc<InferenceResult>;
28 28
29 #[salsa::invoke(crate::infer::can_unify)]
30 fn can_unify(&self, def: DefWithBodyId, ty1: Ty, ty2: Ty) -> bool;
31
29 #[salsa::invoke(crate::lower::ty_query)] 32 #[salsa::invoke(crate::lower::ty_query)]
30 #[salsa::cycle(crate::lower::ty_recover)] 33 #[salsa::cycle(crate::lower::ty_recover)]
31 fn ty(&self, def: TyDefId) -> Binders<Ty>; 34 fn ty(&self, def: TyDefId) -> Binders<Ty>;
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),
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 1e748476a..681f98bde 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -43,7 +43,7 @@ use crate::{
43}; 43};
44 44
45pub use autoderef::autoderef; 45pub use autoderef::autoderef;
46pub use infer::{InferTy, InferenceResult}; 46pub use infer::{unify, InferTy, InferenceResult};
47pub use lower::CallableDefId; 47pub use lower::CallableDefId;
48pub use lower::{ 48pub use lower::{
49 associated_type_shorthand_candidates, callable_item_sig, ImplTraitLoweringMode, TyDefId, 49 associated_type_shorthand_candidates, callable_item_sig, ImplTraitLoweringMode, TyDefId,