diff options
author | adamrk <[email protected]> | 2020-08-22 19:11:37 +0100 |
---|---|---|
committer | adamrk <[email protected]> | 2020-08-30 11:34:32 +0100 |
commit | c6ddb907144688ae77a6de3666159feef53638e1 (patch) | |
tree | a560689c0ff6a35b7ed6a6738c48524730a60263 /crates/hir_ty | |
parent | ac4b134c6be27642dbe915f32a41f9a21bd0c1c9 (diff) |
Add references to fn args during completion
Diffstat (limited to 'crates/hir_ty')
-rw-r--r-- | crates/hir_ty/src/db.rs | 3 | ||||
-rw-r--r-- | crates/hir_ty/src/infer.rs | 15 | ||||
-rw-r--r-- | crates/hir_ty/src/lib.rs | 2 |
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 | ||
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), |
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 | ||
45 | pub use autoderef::autoderef; | 45 | pub use autoderef::autoderef; |
46 | pub use infer::{InferTy, InferenceResult}; | 46 | pub use infer::{unify, InferTy, InferenceResult}; |
47 | pub use lower::CallableDefId; | 47 | pub use lower::CallableDefId; |
48 | pub use lower::{ | 48 | pub use lower::{ |
49 | associated_type_shorthand_candidates, callable_item_sig, ImplTraitLoweringMode, TyDefId, | 49 | associated_type_shorthand_candidates, callable_item_sig, ImplTraitLoweringMode, TyDefId, |