diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-10-27 09:51:49 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-10-27 09:51:49 +0000 |
commit | 8cfc1cd95b6eb9c94f037cfe866c92d51c58c930 (patch) | |
tree | e539dcb18229e328628720661c50d928a72afea1 /crates/hir_ty/src/method_resolution.rs | |
parent | 7f346f9ae17ff9ebaeb24e5bfc4aa56f6ec13191 (diff) | |
parent | ae6376d74cf354a71a83d8c1dcc93589acbce6ea (diff) |
Merge #6376
6376: Avoid impls_fnonce to return true when the trait solving is ambiguous r=flodiebold a=GrayJack
This PR should fix #6375
This adds a variation of `method_resolution::implements_trait` called `method_resolution::implements_trait_unique`, that only returns true when the trait solving is unique, and also change `impls_fnonce` to use the later instead.
I also added a test just to be sure.
Co-authored-by: GrayJack <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/method_resolution.rs')
-rw-r--r-- | crates/hir_ty/src/method_resolution.rs | 13 |
1 files changed, 13 insertions, 0 deletions
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( | |||
740 | solution.is_some() | 740 | solution.is_some() |
741 | } | 741 | } |
742 | 742 | ||
743 | pub fn implements_trait_unique( | ||
744 | ty: &Canonical<Ty>, | ||
745 | db: &dyn HirDatabase, | ||
746 | env: Arc<TraitEnvironment>, | ||
747 | krate: CrateId, | ||
748 | trait_: TraitId, | ||
749 | ) -> bool { | ||
750 | let goal = generic_implements_goal(db, env, trait_, ty.clone()); | ||
751 | let solution = db.trait_solve(krate, goal); | ||
752 | |||
753 | matches!(solution, Some(crate::traits::Solution::Unique(_))) | ||
754 | } | ||
755 | |||
743 | /// This creates Substs for a trait with the given Self type and type variables | 756 | /// This creates Substs for a trait with the given Self type and type variables |
744 | /// for all other parameters, to query Chalk with it. | 757 | /// for all other parameters, to query Chalk with it. |
745 | fn generic_implements_goal( | 758 | fn generic_implements_goal( |