From 957939292ec9038f139bd10e093e9673609eea04 Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Tue, 16 Mar 2021 08:45:46 -0700 Subject: completion relevance consider if types can be unified --- crates/hir_ty/src/infer.rs | 5 +++++ crates/hir_ty/src/infer/unify.rs | 4 ++++ crates/hir_ty/src/lib.rs | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) (limited to 'crates/hir_ty/src') diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index 8f9cf7480..e4407ff50 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs @@ -45,6 +45,11 @@ use crate::{ to_assoc_type_id, to_chalk_trait_id, AliasEq, AliasTy, Interner, TyKind, }; +// This lint has a false positive here. See the link below for details. +// +// https://github.com/rust-lang/rust/issues/57411 +#[allow(unreachable_pub)] +pub use unify::could_unify; pub(crate) use unify::unify; mod unify; diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index 75250a369..6e7b0f5a6 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs @@ -157,6 +157,10 @@ impl Canonicalized { } } +pub fn could_unify(t1: &Ty, t2: &Ty) -> bool { + InferenceTable::new().unify(t1, t2) +} + pub(crate) fn unify(tys: &Canonical<(Ty, Ty)>) -> Option { let mut table = InferenceTable::new(); let vars = Substitution( diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 69265286f..6f9c698e6 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -41,7 +41,7 @@ use crate::{ }; pub use autoderef::autoderef; -pub use infer::{InferenceResult, InferenceVar}; +pub use infer::{could_unify, InferenceResult, InferenceVar}; pub use lower::{ associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode, TyDefId, TyLoweringContext, ValueTyDefId, -- cgit v1.2.3