From 08e95a5dc1035c57f2cfe6f61f0d64280b940b10 Mon Sep 17 00:00:00 2001 From: GrayJack Date: Mon, 26 Oct 2020 15:20:33 -0300 Subject: Fix case where non FnOnce variables is marked callable --- crates/hir/src/code_model.rs | 2 +- crates/hir_ty/src/method_resolution.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 63c1a8ebf..563145f92 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -1398,7 +1398,7 @@ impl Type { }; let canonical_ty = Canonical { value: self.ty.value.clone(), kinds: Arc::new([]) }; - method_resolution::implements_trait( + method_resolution::implements_trait_unique( &canonical_ty, db, self.ty.environment.clone(), diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index 8961df404..5a6f0c67f 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs @@ -740,6 +740,19 @@ pub fn implements_trait( solution.is_some() } +pub fn implements_trait_unique( + ty: &Canonical, + db: &dyn HirDatabase, + env: Arc, + krate: CrateId, + trait_: TraitId, +) -> bool { + let goal = generic_implements_goal(db, env, trait_, ty.clone()); + let solution = db.trait_solve(krate, goal); + + matches!(solution, Some(crate::traits::Solution::Unique(_))) +} + /// This creates Substs for a trait with the given Self type and type variables /// for all other parameters, to query Chalk with it. fn generic_implements_goal( -- cgit v1.2.3