diff options
author | Florian Diebold <[email protected]> | 2019-07-08 20:43:52 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-07-08 20:47:37 +0100 |
commit | 9afbf2dff43dee3227358f10162d4c77d192ce7a (patch) | |
tree | 82d38315b9be21dec920f59389ea89cdb3ae0a41 /crates/ra_hir/src/ty/infer.rs | |
parent | 15862fc04183c7f9b3f3af666336a594a6a52cd9 (diff) |
Unify `normalize` and `implements` to simplify code
Diffstat (limited to 'crates/ra_hir/src/ty/infer.rs')
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 64 |
1 files changed, 18 insertions, 46 deletions
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> { | |||
331 | fn resolve_obligations_as_possible(&mut self) { | 331 | fn resolve_obligations_as_possible(&mut self) { |
332 | let obligations = mem::replace(&mut self.obligations, Vec::new()); | 332 | let obligations = mem::replace(&mut self.obligations, Vec::new()); |
333 | for obligation in obligations { | 333 | for obligation in obligations { |
334 | match &obligation { | 334 | let in_env = InEnvironment::new(self.trait_env.clone(), obligation.clone()); |
335 | Obligation::Trait(tr) => { | 335 | let canonicalized = self.canonicalizer().canonicalize_obligation(in_env); |
336 | let in_env = InEnvironment::new(self.trait_env.clone(), tr.clone()); | 336 | let solution = |
337 | let canonicalized = self.canonicalizer().canonicalize_trait_ref(in_env); | 337 | self.db.solve(self.resolver.krate().unwrap(), canonicalized.value.clone()); |
338 | let solution = self | 338 | |
339 | .db | 339 | match solution { |
340 | .implements(self.resolver.krate().unwrap(), canonicalized.value.clone()); | 340 | Some(Solution::Unique(substs)) => { |
341 | match solution { | 341 | canonicalized.apply_solution(self, substs.0); |
342 | Some(Solution::Unique(substs)) => { | ||
343 | canonicalized.apply_solution(self, substs.0); | ||
344 | } | ||
345 | Some(Solution::Ambig(Guidance::Definite(substs))) => { | ||
346 | canonicalized.apply_solution(self, substs.0); | ||
347 | self.obligations.push(obligation); | ||
348 | } | ||
349 | Some(_) => { | ||
350 | // FIXME use this when trying to resolve everything at the end | ||
351 | self.obligations.push(obligation); | ||
352 | } | ||
353 | None => { | ||
354 | // FIXME obligation cannot be fulfilled => diagnostic | ||
355 | } | ||
356 | }; | ||
357 | } | 342 | } |
358 | Obligation::Projection(pr) => { | 343 | Some(Solution::Ambig(Guidance::Definite(substs))) => { |
359 | let in_env = InEnvironment::new(self.trait_env.clone(), pr.clone()); | 344 | canonicalized.apply_solution(self, substs.0); |
360 | let canonicalized = self.canonicalizer().canonicalize_projection(in_env); | 345 | self.obligations.push(obligation); |
361 | let solution = self | 346 | } |
362 | .db | 347 | Some(_) => { |
363 | .normalize(self.resolver.krate().unwrap(), canonicalized.value.clone()); | 348 | // FIXME use this when trying to resolve everything at the end |
364 | 349 | self.obligations.push(obligation); | |
365 | match solution { | 350 | } |
366 | Some(Solution::Unique(substs)) => { | 351 | None => { |
367 | canonicalized.apply_solution(self, substs.0); | 352 | // FIXME obligation cannot be fulfilled => diagnostic |
368 | } | ||
369 | Some(Solution::Ambig(Guidance::Definite(substs))) => { | ||
370 | canonicalized.apply_solution(self, substs.0); | ||
371 | self.obligations.push(obligation); | ||
372 | } | ||
373 | Some(_) => { | ||
374 | // FIXME use this when trying to resolve everything at the end | ||
375 | self.obligations.push(obligation); | ||
376 | } | ||
377 | None => { | ||
378 | // FIXME obligation cannot be fulfilled => diagnostic | ||
379 | } | ||
380 | }; | ||
381 | } | 353 | } |
382 | }; | 354 | }; |
383 | } | 355 | } |