From c6ddb907144688ae77a6de3666159feef53638e1 Mon Sep 17 00:00:00 2001 From: adamrk Date: Sat, 22 Aug 2020 20:11:37 +0200 Subject: Add references to fn args during completion --- crates/hir_ty/src/db.rs | 3 +++ crates/hir_ty/src/infer.rs | 15 ++++++++++++++- crates/hir_ty/src/lib.rs | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) (limited to 'crates/hir_ty') 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 { #[salsa::invoke(crate::infer::infer_query)] fn infer_query(&self, def: DefWithBodyId) -> Arc; + #[salsa::invoke(crate::infer::can_unify)] + fn can_unify(&self, def: DefWithBodyId, ty1: Ty, ty2: Ty) -> bool; + #[salsa::invoke(crate::lower::ty_query)] #[salsa::cycle(crate::lower::ty_recover)] fn ty(&self, def: TyDefId) -> Binders; 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 { }; } -mod unify; +pub mod unify; mod path; mod expr; mod pat; @@ -78,6 +78,19 @@ pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc bool { + let resolver = def.resolver(db.upcast()); + let mut ctx = InferenceContext::new(db, def, resolver); + + let ty1 = ctx.canonicalizer().canonicalize_ty(ty1).value; + let ty2 = ctx.canonicalizer().canonicalize_ty(ty2).value; + let mut kinds = Vec::from(ty1.kinds.to_vec()); + kinds.extend_from_slice(ty2.kinds.as_ref()); + let tys = crate::Canonical::new((ty1.value, ty2.value), kinds); + + unify(&tys).is_some() +} + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] enum ExprOrPatId { 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::{ }; pub use autoderef::autoderef; -pub use infer::{InferTy, InferenceResult}; +pub use infer::{unify, InferTy, InferenceResult}; pub use lower::CallableDefId; pub use lower::{ associated_type_shorthand_candidates, callable_item_sig, ImplTraitLoweringMode, TyDefId, -- cgit v1.2.3