From 9afbf2dff43dee3227358f10162d4c77d192ce7a Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 8 Jul 2019 21:43:52 +0200 Subject: Unify `normalize` and `implements` to simplify code --- crates/ra_hir/src/ty/infer.rs | 64 ++++++++++++------------------------------- 1 file changed, 18 insertions(+), 46 deletions(-) (limited to 'crates/ra_hir/src/ty/infer.rs') diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index f6cf61ad2..1f74108a4 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs @@ -331,53 +331,25 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { fn resolve_obligations_as_possible(&mut self) { let obligations = mem::replace(&mut self.obligations, Vec::new()); for obligation in obligations { - match &obligation { - Obligation::Trait(tr) => { - let in_env = InEnvironment::new(self.trait_env.clone(), tr.clone()); - let canonicalized = self.canonicalizer().canonicalize_trait_ref(in_env); - let solution = self - .db - .implements(self.resolver.krate().unwrap(), canonicalized.value.clone()); - match solution { - Some(Solution::Unique(substs)) => { - canonicalized.apply_solution(self, substs.0); - } - Some(Solution::Ambig(Guidance::Definite(substs))) => { - canonicalized.apply_solution(self, substs.0); - self.obligations.push(obligation); - } - Some(_) => { - // FIXME use this when trying to resolve everything at the end - self.obligations.push(obligation); - } - None => { - // FIXME obligation cannot be fulfilled => diagnostic - } - }; + let in_env = InEnvironment::new(self.trait_env.clone(), obligation.clone()); + let canonicalized = self.canonicalizer().canonicalize_obligation(in_env); + let solution = + self.db.solve(self.resolver.krate().unwrap(), canonicalized.value.clone()); + + match solution { + Some(Solution::Unique(substs)) => { + canonicalized.apply_solution(self, substs.0); } - Obligation::Projection(pr) => { - let in_env = InEnvironment::new(self.trait_env.clone(), pr.clone()); - let canonicalized = self.canonicalizer().canonicalize_projection(in_env); - let solution = self - .db - .normalize(self.resolver.krate().unwrap(), canonicalized.value.clone()); - - match solution { - Some(Solution::Unique(substs)) => { - canonicalized.apply_solution(self, substs.0); - } - Some(Solution::Ambig(Guidance::Definite(substs))) => { - canonicalized.apply_solution(self, substs.0); - self.obligations.push(obligation); - } - Some(_) => { - // FIXME use this when trying to resolve everything at the end - self.obligations.push(obligation); - } - None => { - // FIXME obligation cannot be fulfilled => diagnostic - } - }; + Some(Solution::Ambig(Guidance::Definite(substs))) => { + canonicalized.apply_solution(self, substs.0); + self.obligations.push(obligation); + } + Some(_) => { + // FIXME use this when trying to resolve everything at the end + self.obligations.push(obligation); + } + None => { + // FIXME obligation cannot be fulfilled => diagnostic } }; } -- cgit v1.2.3